In C ++ 11 and later, you can use the following to generate the default constructor without parameters:
C() = default;
This is more accurate than C () {}.
This does not initialize the participants. In C ++ 11, you can initialize elements in a single line of declaration:
int m_member = 0; // this is a class member
These 2 functions eliminate the need to create your own constructor without parameters to initialize the default members. Thus, your class may look like this when applying these two functions:
class C
{
private:
string A;
double B = 0;
public:
C() = default;
C(string, double);
}
source
share