|
-
February 22nd, 2006, 09:26 PM
#1
once virtual, always virtual?
So, I was recently reading mozilla's portability FAQ and item #25 surprised me and I was wondering if anyone could lend some insight to what I have always thought in the past.
http://www.mozilla.org/hacking/porta..._on_subclasses
According to them once something is virtual it will always be which means to me it can therefore not be inlined and will always require a vtable. However, I always thought that in the following example the call to b.foo() would be inlined (and maybe even a->foo() on really tricky optimizing compilers though certainly not to be expected in more complex cases).
Code:
class A
{
public:
virtual void foo() { cout << "A" << endl; }
};
class B
{
public:
void foo() { cout << "B" << endl; }
};
int main()
{
B b;
b.foo();
A* a = &b;
a->foo();
return 0;
}
I do believe them that this might not be entirely portable though I'm not too concerned with that as we only need to support a small number of compilers, but I would like to know if there is a reason that my belief that b.foo() would be inlined is wrong and if so why that might be.
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|