Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Virtual Constructors

Status
Not open for further replies.

Sun

Programmer
Aug 13, 1999
37
0
0
IN
Visit site
Can you have Virtual Constructors,<br>
If yes why ?
 
you mean, not actually write the constructor fucntion in, but still have whatever you're working with (i'm assuming a class...please correct me if i'm worng) still pass through your compiler's debugger?
 
No I mean a virtual constructor,<br>
with the keyword VIRTUAL i.e<br>
class A<br>
{<br>
virtual A()<br>
{<br>
}<br>
}<br>
<br>
I would like to know if you can have this kind of construct or not if nit why ?
 
If you are really interested in virtual constructors, also known as factory function, I would recommend you take a look at Scott Meyers book "Effective C++ (Second Edition)", pp. 149-152.<br>
<br>
He dedicates a few pages to virtual constructors and why you would want to create one. While you can't really put "virtual" on a constructor like you have in your example, the idea is similar. Virtual constructors return pointers to dynamically allocated objects that support the class interface.<br>
<br>
<br>
<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top