先写个不可复制的抽象类,像单例模式的就可以继承这个类
.cpp文件是个继承测试
baseclass.h
#ifndef _BASECLASS_H
#define _BASECLASS_H
#include <stdio.h>
#include <stdlib,h>
#include <iostream>
using namespace std;
class NonCopy
{
protected:
NonCopy() {
}
virtual ~NonCopy() {
}
private:
NonCopy(const NonCopy&) {
}
const NonCopy& operator=(const NonCopy&) {
}
};
#endif // _BASECLASS_H
baseclass.cpp
#include "baseclass.h"
class Test : public NonCopy
{
public:
Test() {
cout << "test" << endl;
}
};
int main()
{
Test test;
return 0;
}
编译:make baseclass
后面有需要添加的基础类再更新
网友评论