I am trying to disable or rather delete the copy constructor of the parent class Card with the line Card(const Card&) = delete;
When I call Quartz* qu = new Quartz();
in the main i get the error that the default constructor is deleted? I find this confusing since I did not think I was defining a default constructor in Card but rather an overload of the copy constructor. Any explanations or workarounds for this much appreciated.
class Card {
public:
Card(const Card&) = delete;
};
class Quartz : public Card {
public:
Quartz() = default;
};
int main() {
Quartz* qu = new Quartz();
}
Default constructor is only implicitly defined if the class has no other constructors. Since you defined a copy constructor, you now need to explicitly define default one, too.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.