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 |
Explain what are the sizes and ranges of the basic c++ data types?
What are the c++ access specifiers?
Design a program to input a date from user in the form day/month/year (e.g. 2/6/2000) and report whether it’s a valid date or not. The program should take account of leap years. You will need to know that a leap year is a year that is exactly divisible by 4, except that century years are only leap years if they are divisible by 400.
What are all predefined data types in c++?
Explain what you mean by a pointer.
Write a corrected statement in c++ so that the statement will work properly. x + y=z;
What is a null object in c++?
What is c++ programming language?
What data structure is fastest, on average, for retrieving data: a) Binary Tree b) Hash Table c) Stack
What are 2 ways of exporting a function from a dll?
What is DlgProc?
diff between pointer and reference in c++?