- 论坛徽章:
- 0
|
本帖最后由 sampher 于 2013-11-21 19:00 编辑
folklore 发表于 2013-11-21 09:31 ![]()
析构函数里 不能 调用Virtual函数的:
class base{
你的这段代码即使写出来,也是编译不过的:
- #include<iostream>
- using namespace std;
- class sss
- {
- public:
- void do_fun(){cout<<__FUNCTION__<<endl;}
- };
- class base{
- public:
- virtual void f() =0;
- ~base(){
- this->f();
- }
- };
- class child:public base{
- public:
- sss abc;
- void f(){
- abc.do_fun();
- }
- };
- int main(int argc, char* argv[])
- {
- base* pb=new child();
- delete pb;
- return 0;
- }
复制代码 我在RHEL5上用GCC4.1编译说有错,f函数没有实现
你能举出一个能编译过能运行并出错的代码片段吗? |
|