#include <string.h>
#include<iostream>
using namespace std;
class noncopyable
{
private:
noncopyable(const noncopyable& non) {}
noncopyable& operator=(const noncopyable &) {}
public:
noncopyable(){}
virtual ~noncopyable(){}
};
class Exception :public noncopyable
{
protected:
char *message;
public:
Exception(const char *msg)
{
message=new char[1024];
strcpy(this->message,msg);
cout<<"error:"<<msg<<endl;
}
Exception(const string& msg)
{
message=new char[1024];
strcpy(this->message,msg.c_str());
cout<<"error:"<<msg.c_str()<<endl;
}
void printstack()
{
cout<<"error:"<<message<<endl;
}
~Exception(){}
};
void doexception(Exception e)
{
}
class Exception;
int main()
{
Exception excp(string("song"));
doexception(excp);
return 0;
}
拷贝构造函数和赋值构造函数私有化
最新推荐文章于 2021-06-24 09:50:05 发布