Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > virtual functions and dynamic binding

Reply
Thread Tools

virtual functions and dynamic binding

 
 
mescaline
Guest
Posts: n/a
 
      12-28-2003
If a function is declared a virtual function, in what cases will
(some) compilers still do static binding?

thanks
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      12-29-2003
"mescaline" <(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
 
Ron Natalie
Guest
Posts: n/a
 
      12-29-2003

"Victor Bazarov" <(E-Mail Removed)> 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.

 
Reply With Quote
 
Nick Hounsome
Guest
Posts: n/a
 
      12-29-2003

"mescaline" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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



 
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
private virtual functions and pure virtual functions with bodies John Goche C++ 10 12-08-2006 04:00 PM
virtual functions and dynamic binding Mike Stevenson C++ 2 06-23-2006 02:39 PM
calling virtual destructors and virtual functions marcwentink@hotmail.com C++ 3 01-31-2006 04:50 PM
Data Binding - using inline code vs. functions vs. straight binding Jordan ASP .Net 2 02-10-2004 08:32 PM
Virtual functions and virtual base classes - I'm confused Michael Winter C++ 9 09-23-2003 11:17 PM



Advertisments