Invoking constructor from another constructor

This is a discussion on Invoking constructor from another constructor within the C++ Programming forums, part of the General Programming Boards category; So apparently Code: Foo(int x){ ... } Foo(int x, int y) : Foo(x) {....} is not valid. Yet this is ...

  1. #1
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591

    Invoking constructor from another constructor

    So apparently
    Code:
    Foo(int x){ ... }
    Foo(int x, int y) : Foo(x) {....}
    is not valid. Yet this is allowed for base class initialization (trivially, Foo is a base class of itself.)
    Why is this? I mean there must be some good reason as I can't imagine Bjarne in his infinite wisdom would deny such a handy construct....

    p.s. the best alternative I could find was using a common"init()" function in all constructors... such a horrid waste of syntax.

  2. #2
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    Ah, okay found it:
    http://www.informit.com/guides/conte...lus&seqNum=296

    It's called "Constructor Delegation" and apparently isn't going to be available until C++0x.
    Heh, that article predicted every single attempt I had tried previously!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 06-10-2008, 09:38 PM
  2. Invoking base class constructor
    By sawer in forum C++ Programming
    Replies: 5
    Last Post: 07-04-2007, 03:40 PM
  3. C++ have a constructor call another constructor
    By QuestionC in forum C++ Programming
    Replies: 4
    Last Post: 05-17-2007, 02:59 AM
  4. Replies: 3
    Last Post: 03-26-2006, 12:59 AM
  5. Need help in classes
    By LBY in forum C++ Programming
    Replies: 11
    Last Post: 11-26-2004, 04:50 AM

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