【发布时间】:2014-09-02 21:25:39
【问题描述】:
假设我有一个 General 类,它包含一个指向抽象类 *_abstract 的指针。 如果我想实现General拷贝构造函数,它是怎么做的?
我尝试了这个,但失败了:
General::General(const General &other)
{
*_abstract = *other._abstract;
}
我也试过了:
General::General(const General &other)
{
*_abstract = new Abstract();
*_abstract = *other._abstract;
}
这是不可能的,因为抽象类初始化(没有构造函数)
【问题讨论】:
标签: class pointers constructor copy abstract