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

Define linked lists with the help of an example.

0 Answers  


What problems might the following macro bring to the application?

0 Answers  


What is the best c c++ compiler for windows?

0 Answers  


Is c++ a high level language?

0 Answers  


When we use Abstract Class and when we use Interface?where we will implement in real time?

0 Answers  






Implement strcmp

3 Answers   Bloomberg, Citadel,


What are the methods of exporting a function from a dll?

0 Answers  


How do you declare a set in c++?

0 Answers  


What is the correct syntax for inheritance a) class aclass : public superclass b) class aclass inherit superclass c) class aclass <-superclass

0 Answers  


What are the manipulators in c++?

0 Answers  


What is class invariant?

1 Answers  


What is the output of: String a1 = "Hello"; String a2 = "world!"; String* s1 = &a2; String& s2 = a1; s1 = &a1; s2 = a2; std::cout << *s1 << " " << s2 << std::endl;

4 Answers   Lehman Brothers,


Categories