英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论