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

Explain the static storage classes in c++.

709


What is iterator c++?

553


Can I uninstall microsoft c++ redistributable?

611


What is the difference between while and do while loop?

560


Explain how would you handle a situation where you cannot call the destructor of a local explicitly?

547






Describe the advantage of an external iterator.

621


What is null pointer and void pointer?

631


What is the rule of three?

576


What are the various situations where a copy constructor is invoked?

610


explain the reference variable in c++?

580


What are exceptions c++?

598


Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array?

614


What do you mean by translation unit?

607


What is the role of C++ shorthand's?

681


Explain class invariant.

588