Calling virtual function from constructor

Y

Yakov Gerlovin

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
 
W

Werner

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
 
Y

Yakov Gerlovin

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top