Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Calling virtual function from constructor (http://www.velocityreviews.com/forums/t754750-calling-virtual-function-from-constructor.html)

Yakov Gerlovin 10-11-2011 07:26 AM

Calling virtual function from constructor
 
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

Werner 10-11-2011 07:53 AM

Re: Calling virtual function from constructor
 
On Oct 11, 9:26*am, Yakov Gerlovin <yakov.gerlo...@gmail.com> 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

Yakov Gerlovin 10-11-2011 09:16 AM

Re: Calling virtual function from constructor
 

>
> 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


All times are GMT. The time now is 06:23 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.