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 |
What is c++ 11 and c++ 14?
Why is "using namespace std;" considered bad practice?
write a program that takes two numbers from user that prints the smallest number
Define token in c++.
In int main(int argc, char *argv[]) what is argv[0] a) The first argument passed into the program b) The program name c) You can't define main like that
What are friend functions in C++?
Difference between an inspector and a mutator
In a class only declaration of the function is there but defintion is not there then what is that function?
Write a program using merge () function to combine the elements of array x[ ] and y[ ] into array z[ ].
To what does “event-driven” refer?
What is copy constructor? Can we make copy constructor private in c++?
Why c++ is better than c language?