开发者

VTABLE for abstract classes C++ [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Does an abstact classes have a VTABLE?

Does a vtable gets created for an abstract class that have pure virtual functio开发者_C百科ns and virtual functions ?

class Abstarct {
public:
   virtual void f() = 0;
   virtual void g() {}
};

Thanks.


I just saw that none of the answers in the other topic clearly answers it.

The answer is: Yes and No.

Since the vtable and vptr is implementation-defined concept and is not mandated by the C++ Standard, so compilers are free to choose any approach as long as it does dynamic dispatching of the virtual functions (pure or otherwise).

So for the compilers which implement vtable and vptr, the answer is YES (or most likely, YES) and for other compilers which do not implement vtable & vptr and instead implement dynamic dispatching in some other way, the answer is obviously NO.

See this topic:

How can C++ virtual functions be implemented except vtable?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜