读书人

C++ 承袭 + 虚函数

发布时间: 2013-09-08 15:21:21 作者: rapoo

C++ 继承 + 虚函数

#include<iostream>
#include<string>
using namespace std;

class Platform {
public:
virtual string sysinfo() = 0;
virtual ~Platform() {}
};
class MacOS : public Platform{
public:
string sysinfo() {
return "MacOS owo";
}
~Platform() {}
};
class Windows : public Platform{
public:
string sysinfo() {
return "Windows T_T";
}
~Platform() {}
};

编译错误...
为什么积累中的虚函数 ~Platform() {} 不能写在子类中呢? 继承 类
[解决办法]
得写
~MacOS()
~Windows()

没为什么。
[解决办法]
引用:
Quote: 引用:

得写
~MacOS()
~Windows()

没为什么。


但他那个是继承上面的啊? 那个析构函数不能那样继承吗?能讲解的详细点吗?

析构函数是一个特例的函数,析构函数和构造函数是C++中的两个怪物,无论从他的写法还是使用都不能用一般的思维去使用!

读书人网 >C++

热点推荐