When do we need to have a default constructor?

后端 未结 7 1365
终归单人心
终归单人心 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 14:49

    Compiler generates default constructor in case when you have not define any constructor. But if you have defined any constructor that takes some argument or not. The compiler will use that constructor and will not generate default constructor with zero argument.

提交回复
热议问题