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 difference between malloc()/free() and new/delete?

735


What is #include iostream h in c++?

729


Are strings immutable in c++?

748


Why we use #include conio h in c++?

692


Can I learn c++ as my first language?

742






Is swift faster than go?

717


What is difference between class and structure in c++?

723


What is the prototype of printf function?

750


What is operators in c++?

668


How to tokenize a string in c++?

691


Which of the following is evaluated first: a) && b) || c) !

1938


Is c++ fully object oriented?

645


What do you mean by storage classes?

928


What is name hiding in c++?

737


Explain the auto storage classes in c++.

707