pure virtual function can has a function body
2017-04-19 18:48
239 查看
轉載自http://stackoverflow.com/questions/5481941/c-pure-virtual-function-have-body
Your assumption that pure virtual function cannot be called is absolutely incorrect. When a function is declared pure virtual, it simply means that this function cannot get called dynamically, through a virtual dispatch
mechanism. Yet, this very same function can easily be called statically, without virtual dispatch.
In C++ language static call to a virtual function is performed when a qualified name of the function is used in the call, i.e. when the function name specified in the call has the
For example
Your assumption that pure virtual function cannot be called is absolutely incorrect. When a function is declared pure virtual, it simply means that this function cannot get called dynamically, through a virtual dispatch
mechanism. Yet, this very same function can easily be called statically, without virtual dispatch.
In C++ language static call to a virtual function is performed when a qualified name of the function is used in the call, i.e. when the function name specified in the call has the
<class name>::<function name>form.
For example
struct S { virtual void foo() = 0; }; void S::foo() { // body for the pure virtual function `S::foo` } struct D : S { void foo() { S::foo(); // static call to `S::foo` from derived class } }; int main() { D d; d.S::foo(); // another static call to `S::foo` }
相关文章推荐
- Qt Runtime Error ! R6025 - pure virtual function call
- 【转】纯虚函数调用 pure virtual function call 错误
- The error “Pure Virtual Function Called” about C++
- C++ 纯虚函数 pure virtual function && ABC
- C# abstract class cant obtain virtual method without body!!!
- Box2d CreateFixture 发生错误 Debug Error:R6025 pure virtual function call 解决办法
- "Pure Virtual Function Called": An Explanation
- NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
- 运行opencv程序后出现runtime error! R6025-pure virtual function call 错误提示的解决方法
- C++: Pure Virtual Function Called
- What is a pure virtual function?
- First chance exception & R6025-pure virtual function call的问题 Opencv
- [C++] Pure Virtual Function and Abstract Class
- "Pure Virtual Function Called" 纯虚函数调用错误分析(翻译)
- pure virtual function&amp;…
- 一篇非常不错的探讨pure virtual function call错误的文章。
- 【error C2084: function 'Stock::~Stock(void)' already has a body】
- Pure Virtual Function Called--是谁的错?
- eclipse 中 r6025 pure virtual function call 错误的解决方法[转]
- mindmanager的R6025 - pure virtual function call错误解决办法