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 |
given the code segment below void main() { cout<<"my no. is"; } question is how can we get the output hai aravind my no. is 99999999999 without editig the main().
What are the advantages of c++? Explain
What is rtti in c++?
Evaluate !(1&&1||1&&0) a) Error b) False c) True
what is a reference variable in C++?
Explain the difference between using macro and inline functions?
What is an adjust field format flag?
what is the difference between overloading & overriding? give example.
Which ide is best for c++?
What is pure virtual function? Or what is abstract class?
How come you find out if a linked-list is a cycle or not?
What is the difference between new() and malloc()?