By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,187 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

virtual functions and dynamic binding

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

thanks
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"mescaline" <ap*****@columbia.edu> wrote...
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
Jul 22 '05 #2

P: n/a

"Victor Bazarov" <v.********@comAcast.net> wrote in message news:fLKHb.108$xX.800@attbi_s02...
\

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.

Jul 22 '05 #3

P: n/a

"mescaline" <ap*****@columbia.edu> wrote in message
news:e5**************************@posting.google.c om...
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();
thanks

Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.