Why constructor can not be defined as virtual

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 42
Reputation: littlestone is an unknown quantity at this point 
Solved Threads: 6
littlestone littlestone is offline Offline
Light Poster

Why constructor can not be defined as virtual

 
0
  #1
Jul 28th, 2008
Why constructor can not be defined as virtual?

Thanks
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,413
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1470
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Why constructor can not be defined as virtual

 
0
  #2
Jul 28th, 2008
google is a wonderful invention

A constructor cannot be virtual because at the time when the constructor is invoked the virtual table would not be available in the memory. Hence we cannot have a virtual constructor.
http://www.codersource.net/published...ctions_in.aspx
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 42
Reputation: littlestone is an unknown quantity at this point 
Solved Threads: 6
littlestone littlestone is offline Offline
Light Poster

Re: Why constructor can not be defined as virtual

 
0
  #3
Jul 28th, 2008
Thank you so much.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 107
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

Re: Why constructor can not be defined as virtual

 
0
  #4
Jul 29th, 2008
I think the only way to create a "virtual constructor" is to make a virtual method that returns the object inquestion, where derived classes return a copy of their type instead of the base classes return implementation.

By casting a derived type to a base type and invoking the virtual constructor method, you're constructing an object virtually, therefore it's safe to say it is a "virtual constructor".
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC