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 c++ redistributable?

884


Briefly describe a B+ tree. What is bulk loading in it?

996


What is the difference between a definition and a declaration?

822


What is late binding c++?

736


What is runtime errors c++?

817


What is the difference between global int and static int declaration?

635


What is the maximum combined length of command line arguments including the space between adjacent arguments?

787


What is c++ vb?

848


How do you sort a sort function in c++ to sort in descending order?

792


What is a static element?

807


What are the basics of local (auto) objects?

844


What is main function in c++ with example?

839


Can I have a reference as a data member of a class? If yes, then how do I initialise it?

931


Comment on c++ standard exceptions?

870


Define the operators that can be used with a pointer.

805