【发布时间】:2021-02-15 22:07:46
【问题描述】:
我在我的数据结构类中注意到很多,它们声明了构造函数和析构函数。顺便说一下,这是针对 C++ 的。
【问题讨论】:
-
这能回答你的问题吗? What is The Rule of Three?
-
答案将取决于您希望类对象在构造后处于什么状态。如果您对没有构造函数的默认行为感到满意,那么就没有必要编写构造函数; OTOH,如果您需要明确指定构造行为,那么编写构造函数就是这样做的方法。
-
这能回答你的问题吗? Should i define the default constructor?
标签: c++ class constructor