When do we need to have a default constructor?

后端 未结 7 1352
终归单人心
终归单人心 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:57

    See this for the full behaviors of C++ WRT constructors: http://en.wikipedia.org/wiki/Default_constructor

    The simple answer is that if you specify a constructor, the compiler will not create a default one for you.

    This rule applies to Java as well.

提交回复
热议问题