Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Is map thread safe c++?

0 Answers  


Explain the ISA and HASA class relationships. How would you implement each in a class design?

3 Answers  


How the memory management in vectors are being done. What happens when the heap memory is full, and how do you handle it ?

0 Answers   Yahoo,


What are exceptions c++?

0 Answers  


Enter n no. of element and delete value from desire position

1 Answers  


When to use “const” reference arguments in a function?

0 Answers  


Explain public, protected, private in c++?

0 Answers  


When does a name clash occur?

1 Answers  


How can you find the nodes with repetetive data in a linked list?

1 Answers   Lucent,


What is an inclusion guard?

0 Answers  


What is a pure virtual function? Why is it represented as = 0...how is the internal implementation for the same

3 Answers   CTS,


How is modularity introduced in C++?

0 Answers   TCS,


Categories