Calling virtual function from constructor

Discussion in 'C++' started by Yakov Gerlovin, Oct 11, 2011.

  1. Hello,

    I'm trying to find what exactly the standard says about calling of
    virtual function from constructor, but couldn't find anything specific
    in the standard. (I'm looking at ISO 14882, first edition 1998-09-01)

    In 10.4 (Abstract classes) par 6 it says

    "Member functions can be called from a constructor (or destructor) of
    an abstract class; the effect of making a virtual call (10.3) to a
    pure virtual function <...> for the object being created (or
    destroyed) from such a constructor (or destructor) is undefined"

    That implies that according to standard, calling not pure virtual
    function in constructor is OK, but I'd like to see the explicit
    statement if there is one.

    Thank you for your help.

    P.S.
    This is strictly for purpose of academic discussion (and I did tests
    on several compilers and platforms)
    The question is what the standard says and not about how compilers
    implements this case
    Yakov Gerlovin, Oct 11, 2011
    #1
    1. Advertising

  2. Yakov Gerlovin

    Werner Guest

    On Oct 11, 9:26 am, Yakov Gerlovin <> wrote:
    > Hello,
    >
    > I'm trying to find what exactly the standard says about calling of
    > virtual function from constructor, but couldn't find anything specific
    > in the standard. (I'm looking at ISO 14882, first edition 1998-09-01)
    >
    > In 10.4 (Abstract classes) par 6 it says
    >
    > "Member functions can be called from a constructor (or destructor) of
    > an abstract class; the effect of making a virtual call (10.3) to a
    > pure virtual function <...> for the object being created (or
    > destroyed) from such a constructor (or destructor) is undefined"
    >
    > That implies that according to standard, calling not pure virtual
    > function in constructor is OK, but I'd like to see the explicit
    > statement if there is one.
    >
    > Thank you for your help.
    >
    > P.S.
    > This is strictly for purpose of academic discussion (and I did tests
    > on several compilers and platforms)
    > The question is what the standard says and not about how compilers
    > implements this case


    Par 12.7:4:

    "Member functions, including virtual functions..., and the object to
    which the call applies is the object under construction..."

    Kind regards,

    Werner
    Werner, Oct 11, 2011
    #2
    1. Advertising


  3. >
    > Par 12.7:4:
    >
    > "Member functions, including virtual functions..., and the object to
    > which the call applies is the object under construction..."
    >

    Werner ,
    thank you very much
    Yakov Gerlovin, Oct 11, 2011
    #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. Andreas Lagemann
    Replies:
    8
    Views:
    466
    Mike Wahler
    Jan 10, 2005
  2. tiwy
    Replies:
    0
    Views:
    433
  3. Alex Vinokur
    Replies:
    8
    Views:
    383
    Alex Vinokur
    Feb 16, 2006
  4. Replies:
    11
    Views:
    684
    James Kanze
    Sep 10, 2006
  5. Generic Usenet Account
    Replies:
    10
    Views:
    2,205
Loading...

Share This Page