64,648
社区成员
发帖
与我相关
我的任务
分享
class Prototype
{
public:
Prototype(string st)
{
str = st;
}
string Get()
{
return str;
}
virtual Prototype * Clone()=0;
virtual ~Prototype(){}
private:
string str;
};
class ConcretePrototype1 : public Prototype
{
public:
ConcretePrototype1(string st) : Prototype(st)
{
}
ConcretePrototype1(const ConcretePrototype1 & proto) // 就这块,提示父类Prototype没有默认构造。
{
member = proto.member;
cout << " ConcretePrototype1 Copy ... " <<endl;
}
Prototype * Clone()
{
member = new ConcretePrototype1(*this);
return member;
}
~ConcretePrototype1()
{}
private:
ConcretePrototype1 * member;
};
class Prototype
{
public:
Prototype(string st)
{
str = st;
}
string Get()
{
return str;
}
virtual Prototype * Clone()=0;
virtual ~Prototype(){}
private:
string str;
};
class ConcretePrototype1 : public Prototype
{
public:
ConcretePrototype1(string st) : Prototype(st)
{
}
ConcretePrototype1(ConcretePrototype1 & proto) : Prototype(proto.Get()) // 这样可以,我脑子唬住了0_o (星雨大哥的不能访问私有成员)
{
member = proto.member;
cout << " ConcretePrototype1 Copy ... " <<endl;
}
Prototype * Clone()
{
member = new ConcretePrototype1(*this);
return member;
}
~ConcretePrototype1()
{}
private:
ConcretePrototype1 * member;
};
#include <string>
#include <iostream>
using namespace std;
class Prototype
{
public:
Prototype():str(""){}//或者这样为父类提供一个默认构造函数
Prototype(string st)
{
str = st;
}
string Get()
{
return str;
}
virtual Prototype * Clone()=0;
virtual ~Prototype(){}
private:
string str;
};
class ConcretePrototype1 : public Prototype
{
public:
ConcretePrototype1(string st) : Prototype(st)
{
}
ConcretePrototype1(const ConcretePrototype1 & proto)
{
member = proto.member;
cout << " ConcretePrototype1 Copy ... " <<endl;
}
Prototype * Clone()
{
member = new ConcretePrototype1(*this);
return member;
}
~ConcretePrototype1()
{}
private:
ConcretePrototype1 * member;
};
#include <string>
#include <iostream>
using namespace std;
class Prototype
{
public:
Prototype(string st)
{
str = st;
}
string Get()
{
return str;
}
virtual Prototype * Clone()=0;
virtual ~Prototype(){}
private:
string str;
};
class ConcretePrototype1 : public Prototype
{
public:
ConcretePrototype1(string st) : Prototype(st)
{
}
ConcretePrototype1(const ConcretePrototype1 & proto):Prototype("") //可以这样用空串来初始化
{
member = proto.member;
cout << " ConcretePrototype1 Copy ... " <<endl;
}
Prototype * Clone()
{
member = new ConcretePrototype1(*this);
return member;
}
~ConcretePrototype1()
{}
private:
ConcretePrototype1 * member;
};
class Prototype
{
public:
Prototype(string st)
{
str = st;
}
string Get()
{
return str;
}
virtual Prototype * Clone()=0;
virtual ~Prototype(){}
private:
string str;
};
class ConcretePrototype1 : public Prototype
{
public:
ConcretePrototype1(string st) : Prototype(st)
{
}
ConcretePrototype1(const ConcretePrototype1 & proto):Prototype(st) // 就这块,提示父类Prototype没有默认构造。
{
member = proto.member;
cout << " ConcretePrototype1 Copy ... " <<endl;
}
Prototype * Clone()
{
member = new ConcretePrototype1(*this);
return member;
}
~ConcretePrototype1()
{}
private:
ConcretePrototype1 * member;
};
class Prototype
{
public:
Prototype(string st)
{
str = st;
}
string Get()
{
return str;
}
virtual Prototype * Clone()=0;
virtual ~Prototype(){}
protected:
string str;
};
class ConcretePrototype1 : public Prototype
{
public:
ConcretePrototype1(string st) : Prototype(st)
{
}
ConcretePrototype1(const ConcretePrototype1 & proto) // 就这块,提示父类Prototype没有默认构造。
: Prototype(proto.str)
{
member = proto.member;
cout << " ConcretePrototype1 Copy ... " <<endl;
}
Prototype * Clone()
{
member = new ConcretePrototype1(*this);
return member;
}
~ConcretePrototype1()
{}
private:
ConcretePrototype1 * member;
};