When do we need to have a default constructor?

后端 未结 7 1337
终归单人心
终归单人心 2020-12-08 14:43

My question is simple. When do we need to have a default constructor? Please refer to the code below:

class Shape
{
    int k;

public:
    Shape(int n) : k         


        
相关标签:
7条回答
  • 2020-12-08 15:09

    The default constructor is generated only if you have not defined any other constructors.

    Supposedly, if you need some special initialization in the class, the default constructor would not do the right thing.

    0 讨论(0)
提交回复
热议问题