抽象类在C++中是否创建默认复制构造函数和赋值运算符?

huangapple go评论102阅读模式
英文:

Are the default copy constructors and assignment operator created for an abstract class in C++?

问题

有一个默认的复制构造函数/赋值运算符,它执行浅复制。这些默认创建的东西甚至用于抽象类吗?

英文:

There is a default copy-constructor/ assignment operator which does a shallow copy.
Are these created by default even for an abstract class?

答案1

得分: 5

一个类被声明为 抽象(即,具有 纯虚拟 方法)并不会改变编译器为该类生成的内容。它只要求该类不能直接实例化,且其纯虚拟方法必须在派生类中被重写。仅此而已。抽象基类仍然必须能够像任何其他类一样被初始化和赋值。

英文:

A class being abstract (ie, having pure virtual methods) doesn't change anything in regards to what the compiler may auto-generate for that class. All it does is require the class to not be instantiated directly, and that its pure virtual methods must be overridden in derived classes. That's it. Abstract base classes must still be able to be initialized/assigned to, like any other class.

huangapple
  • 本文由 发表于 2023年3月10日 01:37:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/75688183.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定