Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Calling virtual function from constructor

Reply
Thread Tools

Calling virtual function from constructor

 
 
Yakov Gerlovin
Guest
Posts: n/a
 
      10-11-2011
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
 
Reply With Quote
 
 
 
 
Werner
Guest
Posts: n/a
 
      10-11-2011
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
 
Reply With Quote
 
 
 
 
Yakov Gerlovin
Guest
Posts: n/a
 
      10-11-2011

>
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A constructor calling another constructor (default constructor)? Generic Usenet Account C++ 10 11-28-2007 04:12 AM
same overhead in calling virtual and non virtual member function...? ypjofficial@indiatimes.com C++ 11 09-10-2006 06:08 PM
Calling virtual function in constructor Alex Vinokur C++ 8 02-16-2006 08:11 PM
calling virtual function results in calling function of base class... Andreas Lagemann C++ 8 01-10-2005 11:03 PM
calling virtual function results in calling function of base class ... tiwy C++ 0 01-09-2005 11:17 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57