virtual functions and dynamic binding

M

mescaline

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

thanks
 
V

Victor Bazarov

mescaline said:
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
 
R

Ron Natalie

Victor Bazarov said:
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.
 
N

Nick Hounsome

mescaline said:
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();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Functions 2
virtual functions and dynamic binding 2
Wrapper functions 1
Pure virtual accessors? 5
C Programming functions 2
Non virtual and inheritance 7
Dynamic programming 3
Webview Javascript functions? 1

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top