Is there any virtual constructor ?

This is a discussion on Is there any virtual constructor ? within the C++ Programming forums, part of the General Programming Boards category; hey friends, I want to know is there any 'virtual constructor' in c++? This question has been asked to me ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    1

    Is there any virtual constructor ?

    hey friends,

    I want to know is there any 'virtual constructor' in c++? This question has been asked to me twice in my college. Hope to get reply with sound explanations.

    byeee

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Not really. There's a pattern that can be called virtual constructor, but it is not inherently supported by the language.

    "Modern C++ Design" by Andrei Alexandrescu contains an implementation of the pattern.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    no, and you can't call virtual functions inside constructors either. The reason is that the vtable has not been assembled yet. There are however virtual destructors which in some uses are crucial.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Virtual base class constructor
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 03-24-2008, 02:18 AM
  3. virtual base class constructor
    By George2 in forum Windows Programming
    Replies: 1
    Last Post: 03-24-2008, 12:43 AM
  4. Virtual Base Class & Constructor :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 09-13-2002, 03:14 PM
  5. C++ XML Class
    By edwardtisdale in forum C++ Programming
    Replies: 0
    Last Post: 12-10-2001, 10:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21