Why can you not make a constructor as const?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
Why preincrement operator is faster than postincrement?
what is the diff b/n c and c++ a. dynamic scoping b. nested switching c. declaration of variables in any code block d. separation of compilation and linking
What is c++ and its uses?
What are arithmetic operators?
The "virtual" specifier in a member function enables which one of the following? a) Monmorphism b) Late binding c) Metamorphism d) Solomorphism e) Inheritance
What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro?
What is the purpose of templates in c++?
What is the return value of the insertion operator?
How do you decide which integer type to use?
What is an iterator class in c++?
What is the full form of stl in c++?
List the issue that the auto_ptr object handles?