Why can you not make a constructor as const?

Answer Posted / som shekhar

If the function is declared constant then you are not
intended to change the member variables of the class and if
you did the compiler throws an error.
In this case you can change the variable inside the const
function if the variable is declared as VOLATILE.

Similarly if you declare a variable as const then you cannot
change the value of the variable through its life time.

Now if you declared the constructor then you cannot
initialize the object.

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is an html tag?

623


Explain about templates of C++.

670


Can the operator == be overloaded for comparing two arrays consisting of characters by using string comparison?

554


Are vectors faster than arrays?

565


When do you call copy constructors?

637






What is a base class?

595


State the difference between delete and delete[].

567


Refer to a name of class or function that is defined within a namespace?

591


What is difference between malloc()/free() and new/delete?

640


Show the declaration for a static member variable.

518


Describe the advantages of operator overloading?

568


What is constructor c++?

661


What is c++ good for?

577


Why can’t you call invariants() as the first line of your constructor?

546


Is it possible to use a new for the reallocation of pointers ?

589