От: | Анатолий Широков | ||
Дата: | 17.02.04 22:10 | ||
Оценка: |
class C1
{
public:
virtual ~C1() {}
virtual C1* clone() const
{
return new C1(*this);
}
};
class C2 : public C1
{
public:
virtual C1* clone() const
{
return new C2(*this);
}
};
inline C1* clone(const C1 *ptr)
{
return ptr->clone();
}
int main()
{
C1* c1 = new C1;
C2* c2 = new C2;
C1* clone1 = clone(c1);
C1* clone2 = clone(c2);
delete clone1;
delete clone2;
delete c1;
delete c2;
return 0;
}