473,473 Members | 1,808 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

virtual functions and dynamic binding

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

thanks
Jul 22 '05 #1
3 2394
"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

"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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Prabu | last post by:
Hi, I'm new to python, so excuse me if i'm asking something dumb. Does python provide a mechanism to implement virtual functions? Can you please give a code snippet also...:) Thanx in advance...
3
by: CoolPint | last post by:
I read that the return type has to be exactly same for a virtual function to be overriden. While testing something, I discovered something I cannot understand. I cannot understand why the code...
2
by: IK | last post by:
Hello All, Please excuse me for posting this here, but I don't find any other group where I will get a proper answer. This is about clarifying the C++ part of COM. I understand that COM is a...
6
by: Dumitru Sipos | last post by:
Hello everybody! is there possible to have a function that is both static and virtual? Dumi.
9
by: kish_nand | last post by:
Could someone please explain me the concept behind virtual functions and vtables. I am little confused about this. Please refer to the following code and tell me how many virtual tables would be...
16
by: plmanikandan | last post by:
Hi, I have doubts reg virtual constructor what is virtual constructor? Is c++ supports virtual constructor? Can anybody explain me about virtual constructor? Regards, Mani
2
by: Mike Stevenson | last post by:
Hi. I'm in the process of re-learning all the C++ I forgot from college, and I'm starting to get into some virgin (or at least only a couple times) territory. I have some questions about casting...
15
by: Philipp | last post by:
Hello I don't exactly understand why there are no static virtual functions. I would have liked something like this: class Base{ static virtual std::string getName(){ return "Base"; } }
23
by: Dave Rahardja | last post by:
Since C++ is missing the "interface" concept present in Java, I've been using the following pattern to simulate its behavior: class Interface0 { public: virtual void fn0() = 0; };
4
by: wizwx | last post by:
The followings are a few lines of code from the Template method in "Thinking in C++" vol.2 pp.639 class ApplicationFramework { protected: virtual void customize1() = 0; virtual void...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.