When do we need to have a default constructor?

后端 未结 7 1335
终归单人心
终归单人心 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.

提交回复
热议问题