Конструктор для «C» должен явно инициализировать базовый класс «A», который не имеет конструктора по умолчаниюC++

Программы на C++. Форум разработчиков
Anonymous
Конструктор для «C» должен явно инициализировать базовый класс «A», который не имеет конструктора по умолчанию

Сообщение Anonymous »

Я написал этот код, но он не мог скомпилироваться, и я получил эту ошибку в Clang ++ v18.1.3 < /p>
constructor for 'C' must explicitly initialize the base class 'A' which does not have a default constructor
< /code>
class A
{
public:
explicit A(int n)
{}
};

class B : virtual public A
{
public:
B(int n)
: A(n)
{}
};

class C : public B
{
public:
C(int n)
: B(n)
{}
};
< /code>
i could call constructor of A inside constructor of C and it resolve the problem but i do not have any idea why this problem happened and i want to know is there any official way to solve this problem?

Подробнее здесь: https://stackoverflow.com/questions/794 ... h-does-not

Вернуться в «C++»