Why can you not make a constructor as const?

Answers were Sorted based on User's Feedback



Why can you not make a constructor as const?..

Answer / sumit kumar

what happens if we make a constructor as const
then object which is not fully constructed,
inside it you can not initialize the instance variable.

Is This Answer Correct ?    8 Yes 3 No

Why can you not make a constructor as const?..

Answer / 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

Why can you not make a constructor as const?..

Answer / som shekhar

Sorry the keyword is not volatile ,its mutable.
if the member varible of the class is declared as mutable
then you can change its value in a function which is
declared as constant.

Is This Answer Correct ?    4 Yes 0 No

Post New Answer

More C++ General Interview Questions

Explain the operation of overloading of an assignment operator.

0 Answers  


What is a breakpoint?

0 Answers  


Do inline functions improve performance?

0 Answers  


Is c++ proprietary?

0 Answers  


Mention the purpose of istream class?

0 Answers  






Write a C/C++ program to show the result of a stored procedure "PROC_RESET_MAIL" on database "USER_NOTIFY".

2 Answers   ABC, Accenture, DataLand, HCL, Webyog,


How a new element can be added or pushed in a stack?

0 Answers  


What is data binding in c++?

0 Answers  


By using c++ with an example describe linked list?

0 Answers  


Why c++ is so important?

0 Answers  


How compile and run c++ program in turbo c++?

0 Answers  


What is virtual destructors? Why they are used?

1 Answers  


Categories