Welcome, Guest. Please login or register.

Author Topic: question about C++ constructors  (Read 23014 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: question about C++ constructors
« on: January 24, 2003, 10:48:59 AM »
Quote

DaveP wrote:
...
By doing it this way not only do you need to worry about deallocation during a stack unwind or the messy business of supporting exception throwing on a constructor but you have nicely introduced yourself to the concepts of "Homes" and "Factories" for object instances so beloved of Distributed OO.


Also, factories are very well worth a look because of a very cool feature that everbody getting into OOP craves at some point - the 'virtual' constructor. In reality, a virtual constructor is impossible since the compiler must know the exact object to be instansiated.
However, A factory can take a pointer to an existing polymorphic object and return a pointer to a new instance of the same class (usually via some virtual function magic).
There are several ways of doing this, I found that the method described in Bjaarne Stroustrup's 'The C++ Programming Language' 3rd Ed. works for me...
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: question about C++ constructors
« Reply #1 on: January 24, 2003, 03:15:20 PM »
@Treke

Thanks. Looks interesting, I'll give it a look.
int p; // A