The following compiler says that my constructor for derived classes was not found:
struct Drink
{
Drink(const Drink& other);
};
struct PepsiMax : Drink {};
int main()
{
PepsiMax myPepsi;
}
I know that the default Drink constructor must be defined because I created the copy constructor and the compiler will not use the default constructor for me. However, the error message says that it cannot find the default constructor for my PepsiMax class, which I expected from it. If I define a default constructor for PepsiMax, it shows an error saying that it cannot find the default Drink constructor that I expect.
Can we assume that it refers to the default constructor of "Drink", and not to "PepsiMax", or am I not understanding something? I expected the compiler to create a default constructor for "PepsiMax", which immediately calls the base class constructor as the first thing it does.
Edit: I'm confused, thanks for your help. My explanation of my naive interpretation of the constructor created by the compiler is in the answer.
source
share