定义一个不可复制的基类
class Uncopyable
{
public:
protected:
Uncopyable(){};
~Uncopyable(){};
private:
Uncopyable(const Uncopyable &);
Uncopyable& operator=(const Uncopyable &);
};
以后继承这个类的都会不可复制
class Phone:private Uncopyable
{
public:
Phone():number(),version(){
}
void SetVersion(const std::string &v){
this->version = v;
}
std::string GetVersion()const{
return this->version;
}
protected:
private:
std::string number;
std::string version;
};
main函数里面这样用编译时会报错
Phone p1;
Phone p2(p1);//error
p2 = p1; //error