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...

Can we have "Virtual Constructors"?

Answer Posted / bharat

People have already posted the answer in brief, however for
a newbie, this might not be enough... Hence posting this
thread...

If you are referring to constructors as in pure C++, then
there is no such concept as "virtual" constructors. A
constructor is responsible for creation of the particular
object, and hence cannot be "virtual".

It cannot be so, because a virtual function allows the
actual function call to be "deeper" in the hierarchy than
the type through which it is being called. for example, you
can have a base pointer through which a virtual call is made
to a derived object's function code (Derived class is
"deeper" than base class")

Since the constructor is responsible for creation of the
object itself, the function call being "deeper" than the
type being created does not make any sense. Hence a
constructor is always "local", and virtual constructor
concept does not exist.


However, in the domain of design patterns, there is such a
concept as Virtual Constructor or Factory Method. You can
find more information on this concept in "Thinking in C++
Volume 2" (A superb and Free ebook by Bruce Eckel) at the
location

http://www.planetpdf.com/developer/article.asp?ContentID=6634

Hope this is useful...

Is This Answer Correct ?    9 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

If you push the numbers (in order) 1, 3, and 5 onto a stack, which pops out first a) 1 b) 5 c) 3

1370


Which is most difficult programming language?

1088


What is static function? Explain with an example

1056


What is a dll entry point?

987


How is new() different from malloc()?

1104


Explain about Garbage Collector?

1109


What is an undefined reference/unresolved external symbol error and how do I fix it?

1110


What is the difference between an external iterator and an internal iterator?

1094


Explain rtti.

1065


How can a called function determine the number of arguments that have been passed to it?

1124


How does class accomplish data hiding in c++?

1165


What are destructors?

987


What is the size of integer variable?

1050


Why c++ is better than c language?

1010


What is function overloading in C++?

1405