Empty Constructors in C++:

In C++11 and later you can use the following to generate a default no-param constructor:

C() = default;

This is neater than C(){}.

This doesn't initialize members. In C++11 you can initialize members in the same line of declaration:

int m_member = 0; // this is a class member

Those 2 features avoids having to create your own no param constructor to default initialize members. So your class can look like this when applying those 2 features:

class C
{
private:
    string A;
    double B = 0;

public:
   C() = default;
   C(string, double);  
}

It is fine to do this and leave the constructor empty, but you should be aware that uninitialized fields have undefined value. string is a class and it's default constructor takes care of its initialization, but double is not initialized here (in your defualt constructor), and its value is undefined (it may be whatever value previously exists in the memory).


Your empty constructor does not do what you want. The double data member will not be zero-initialized unless you do it yourself. The std::string will be initialized to an empty string. So the correct implementation of the default constructor would simply be

C::C() : B() {} // zero-initializes B

Concerning the other constructor, you should prefer the initialization list:

C::C(const string& a, double b) : A(a), B(b) {}

otherwise, what you are doing is an assignment to default constructed objects.