virtual copy constructor?
在基类中加个virutal fund* clone() const = 0;然后每个类以协变的方式实现就行了,比如:
class fund {
public:
...
virtual fund* clone() const = 0;
...
}
class motherfund : public fund {
public:
...
virtual motherfund* clone() const = 0
{
return new motherfund(*this);
}
...
};
...
int main()
{
motherfund mf(...);
motherfund* pmf2 = mf.clone();
...
delete pmf2;
}
在基类中加个virutal fund* clone() const = 0;然后每个类以协变的方式实现就行了,比如:
class fund {
public:
...
virtual fund* clone() const = 0;
...
}
class motherfund : public fund {
public:
...
virtual motherfund* clone() const = 0
{
return new motherfund(*this);
}
...
};
...
int main()
{
motherfund mf(...);
motherfund* pmf2 = mf.clone();
...
delete pmf2;
}

My life is brilliant