| View previous topic :: View next topic |
| Author |
Message |
mescaline Guest
|
Posted: Sun Dec 28, 2003 11:45 pm Post subject: virtual functions and dynamic binding |
|
|
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
|
Posted: Mon Dec 29, 2003 12:41 am Post subject: Re: virtual functions and dynamic binding |
|
|
"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
|
Posted: Mon Dec 29, 2003 2:19 am Post subject: Re: virtual functions and dynamic binding |
|
|
"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
|
Posted: Mon Dec 29, 2003 5:53 pm Post subject: Re: virtual functions and dynamic binding |
|
|
"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();
|
|
| Back to top |
|
 |
|