#include <iostream>
using namespace std;
class noncopyable
{
public:
noncopyable(const noncopyable&) = delete;
void operator=(const noncopyable&) = delete;
//构造函数是protected的,因为这个类不需要被实例化,但是又需要能让子类实例化
protected:
noncopyable() = default;
~noncopyable() = default;
};
//子类继承noncopyable类,调用拷贝构造函数时,找不到父类的拷贝构造函数就会报错
class classA : public noncopyable
{
public:
classA() {};
classA(int i) { a = i; };
public:
int a;
};
int main()
{
classA a1;
classA a2(1);
//classA a3 = a1; //error
//classA a4(a1); //error
system("pause");
return 0;
}