calling overloaded constructor from constructor

Discussion in 'C++' started by Michael Wild, Dec 7, 2005.

  1. Michael Wild

    Michael Wild Guest

    hi everybody

    i suppose this question has been answered a countless times, but i can't
    seem to find the answer...

    how do i call an overloaded version of a constructor from a constructor?
    suppose something like this:

    class A
    {
    int field;
    A(int i){field = i;}
    A()
    {
    // and here comes the guesswork:
    A(1);
    }
    };

    what i want to do is calling another constructor with default arguments.

    thanks for any help and hints

    - michael
    Michael Wild, Dec 7, 2005
    #1
    1. Advertising

  2. * Michael Wild:
    >
    > i suppose this question has been answered a countless times, but i can't
    > seem to find the answer...
    >
    > how do i call an overloaded version of a constructor from a constructor?


    Within the same class you can't.

    You can introduce an artificial base class, use default values, or use
    an init-function.

    The latter is a FAQ.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
    Alf P. Steinbach, Dec 7, 2005
    #2
    1. Advertising

  3. Michael Wild

    Michael Wild Guest

    Alf P. Steinbach wrote:
    > * Michael Wild:
    >> i suppose this question has been answered a countless times, but i can't
    >> seem to find the answer...
    >>
    >> how do i call an overloaded version of a constructor from a constructor?

    >
    > Within the same class you can't.
    >
    > You can introduce an artificial base class, use default values, or use
    > an init-function.
    >
    > The latter is a FAQ.
    >


    Thanks. I'll stick with the init function then.
    Michael Wild, Dec 7, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. matt p
    Replies:
    3
    Views:
    462
    =?ISO-8859-15?Q?Juli=E1n?= Albo
    Nov 7, 2004
  2. ES Kim
    Replies:
    3
    Views:
    276
    Jonathan Mcdougall
    May 23, 2006
  3. Generic Usenet Account
    Replies:
    10
    Views:
    2,202
  4. Afshin
    Replies:
    0
    Views:
    286
    Afshin
    Aug 12, 2011
  5. Afshin
    Replies:
    0
    Views:
    287
    Afshin
    Aug 12, 2011
Loading...

Share This Page