shuisheng wrote:
If I define a virtual function to be inline, is it really inline?
No function you *declare* 'inline' is really inline. There is no way
in the language to find out. The compiler will do what it wants.
Or
it is inline in some cases, and not in other cases. Would you please
help me to look at the following case.
struct A
{
int i;
A() {i = 0;}
virtual void Add() {i++;}
};
struct B : public A
{
virtual void Add() {i += 2;}
};
int main()
{
A a;
a.Add(); // inline ?
Yes, very likely.
>
B b;
b.Add(); // inline ?
Yes, very likely.
>
A *pa = new A();
pa->Add(); // not inline?
A *pb = new B();
pb->Add(); // not inline?
return 0;
}
The last two cases, I don't know, but I suspect that only the
last time the call will be non-inlined (polymorphic). Both
cases are possible to track since 'pa' and 'pb' are local objects,
and the compiler _may_ be written to track those things, but no
guarantees can be given.
Ask your compiler to generate assembly code for you and look.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask