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

Which is the best c++ compiler for beginners?

0 Answers  


Write a program using shift_half( ) function to shift the elements of first half array to second half and vice versa.

0 Answers  


What is the extraction operator and what does it do?

0 Answers  


What is the role of C++ shorthand's?

0 Answers   TCS,


What is a try block?

0 Answers  






1.Between 100 and 999 are some numbers that have the characteristics that if you cube the individual digits and sum together you will get the same number. 2. A program that can accept as input an integer and output the equivalent of that number in words.

3 Answers  


What is function overriding?

1 Answers  


Can I uninstall microsoft c++ redistributable?

0 Answers  


Explain the different access specifiers for the class member in c++.

0 Answers  


What is vector processing?

0 Answers  


Program to check whether a word is a sub-string or not of a string typed

0 Answers  


a class that maintains a pointer to an object that is programatically accessible through the public interface is known as?

2 Answers   CTS,


Categories