C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

virtual functions and dynamic binding

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
mescaline
Guest





PostPosted: Sun Dec 28, 2003 11:45 pm    Post subject: virtual functions and dynamic binding Reply with quote



If a function is declared a virtual function, in what cases will
(some) compilers still do static binding?

thanks
Back to top
Victor Bazarov
Guest





PostPosted: Mon Dec 29, 2003 12:41 am    Post subject: Re: virtual functions and dynamic binding Reply with quote



"mescaline" <apt2003 (AT) columbia (DOT) edu> wrote...
Quote:
If a function is declared a virtual function, in what cases will
(some) compilers still do static binding?

All compilers bind statically if a virtual function is called
from a constructor or a destructor, or if it's called using
fully qualified name (IIRC).

Victor



Back to top
Ron Natalie
Guest





PostPosted: Mon Dec 29, 2003 2:19 am    Post subject: Re: virtual functions and dynamic binding Reply with quote




"Victor Bazarov" <v.Abazarov (AT) comAcast (DOT) net> wrote


Quote:

All compilers bind statically if a virtual function is called
from a constructor or a destructor,

Only if called directly from the constructor or destructor. However,
virtual functions are not disabled during construction, the only thing that
changes is that the effective type of the object is the class that the constructor
/destructor is being executed for.

struct B {
virtual void v();
void nv() { v(); }
};

struct D : B {
void v();
D() { nv(); } // results in D::v() getting called.


Back to top
Nick Hounsome
Guest





PostPosted: Mon Dec 29, 2003 5:53 pm    Post subject: Re: virtual functions and dynamic binding Reply with quote


"mescaline" <apt2003 (AT) columbia (DOT) edu> wrote

Quote:
If a function is declared a virtual function, in what cases will
(some) compilers still do static binding?


When they know what the actual function must be - e.g ctor,dtor or just

X x;
x.aVirtualFunction();

Quote:
thanks



Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.