抽象类,复制构造函数 [英] Abstract class, copy constructor

查看:95
本文介绍了抽象类,复制构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在具有纯虚方法的类中或仅在派生类中定义副本构造函数/运算符=有意义吗?

Does it make sense to define a copy constructor / operator = in class having pure virtual method or only in derived classes?

推荐答案

如果它只有纯虚方法(没有数据成员),那么不,综合的方法很好(不会做任何事情)。

If it has only pure virtual methods (and no data members) then, no, the synthesised one is fine (and won't do anything).

如果有数据成员,那么您应该在必要时定义自己的副本构造函数,就像其他任何类一样。派生类与它并没有多大关系。

If it does have data members then you should define your own copy constructor if/when it makes sense to do so, just like for any other class. Derived classes don't really have much to do with it.

这篇关于抽象类,复制构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆