C++ – So can a class have two default constructors

c++

I'm reading my book and it says "A constructor that supplies default arguments for all its parameters also defines the default constructor"

so in the following code:

class Book {

    public: 

    int pages = 25;
    double price = 10.0;
    std::string font = "Times New Roman";

    Book() {}
    Book(int n, double p, std::string f): pages(n), price(p), font(f) { }
};

Both the constructor that takes no parameters and the constructor that supplies default arguments for its parameters are default constructors? Or by default arguments does it mean that the second constructor would need to look something like: Book(): pages(5), price(46), font("Times New Roman") {}

Best Solution

The funny thing is that your class can have multiple constructor overload which could work with no arguments and are therefore valid default constructors:

struct A
{
    A() {}
    A( int i = 0 ) {}
};

This is perfectly legal to write. The answer to the question from the title is therefore: Yes. The only problem is that you can not use them - they are ambiguous. When you write:

A a;

you get an error as both would match.