| ||||
| 刚才我同事问我的一个问题,分享一下: Typically if a class has a pure virtual dtor, you can’t create instance of this class. It is designed as an abstract class. But you must provide a default implementation for that class, or the compiler will generate error: Example: c++ 代码:
undefined reference to `Base::~Base()` You must over write the dtor in derived classes as the following: c++ 代码:
And the result is as below: liuuuxin@WEIFANG ~/temp $ g++ test.cpp -o test liuuuxin@WEIFANG ~/temp $ ./test Foo closed Bar closed 顺便引一下标准: The standard says in section 12.4 [class.dtor] para 7 page 192: "A destructor can be declared virtual (10.3) or pure virtual (10.4) ..."
__________________ ================================== http://liuxinyu95.googlepages.com liuxinyu95@gmail.com ================================== |
![]() |
| 书签 |
| 主题工具 | |
| 显示模式 | |
| |
相似的主题 | ||||
| 主题 | 主题作者 | 版面 | 回复 | 最后发表 |
| 谁说C++没有foreach? | Unsigned | C/CPP/TMP/GP | 13 | 2006-07-12 07:17 PM |
| 捕捉鼠标输入的方法 | bankrock | 技术杂烩 | 33 | 2005-06-16 03:32 PM |
| 练习三:大家都知道virtual function,怎样实现virtual data? | abp | 技术杂烩 | 18 | 2004-07-02 05:49 PM |
| 多重继承其中一个基类是virtual继承. | andy84920 | 技术杂烩 | 7 | 2004-03-01 03:26 PM |
| 容器中放入同一個template class產生的對象? | sad | 技术杂烩 | 9 | 2003-03-26 09:40 PM |