SI
SI
discoversearch

We've detected that you're using an ad content blocking browser plug-in or feature. Ads provide a critical source of revenue to the continued operation of Silicon Investor.  We ask that you disable ad blocking while on Silicon Investor in the best interests of our community.  If you are not using an ad blocker but are still receiving this message, make sure your browser's tracking protection is set to the 'standard' level.
Technology Stocks : BORL: Time to BUY!

 Public ReplyPrvt ReplyMark as Last ReadFilePrevious 10Next 10PreviousNext  
To: Neil Booth who wrote (8335)12/31/1997 12:00:00 PM
From: David R  Read Replies (2) of 10836
 
Neil, I understand completely what youare saying. However, when you are calling a virtual function of a class through its base class pointer, I do not believe that the compiler can resolve the function call. Hence, it requires a runtime lookup.

Consider:

class a{virtual int foo(){return 1;}};
class b : public a {virtual int foo() {return 2;}};

class a* pa1, pa2;
class b* pb1;
int res1, res2, res3;
pa1 = new a;
pb1 = new b;
pa2 = pb1;

res1 = pa1->foo();
res2 = pa2->foo();
res3 = pb1->foo();

The results are res1 = 1, res 2 = 2, and res3 = 2. However, unless I am seriously mistaken (of which I consider the possibility), res2 requires a runtime determination as to which foo to call (aka which vtable to dereference). The compiler has no way of knowing if pa2 (or pa1 for that matter) will contain a base class or a derived class at runtime. All C++ code can not be resolved at compile time, there is some runtime overhead. That is a fact of which I am quite sure.
Report TOU ViolationShare This Post
 Public ReplyPrvt ReplyMark as Last ReadFilePrevious 10Next 10PreviousNext