Пример здесь не имеет смысла, но именно так я и написал свою программу на Python, и сейчас я переписываю ее на C ++. Я все еще пытаюсь понять множественное наследование в C ++, и здесь мне нужно получить доступ к A :: a_print из main через экземпляр C. Ниже вы увидите, о чем я говорю. Возможно ли это?
#include <iostream>
using namespace std;
class A {
public:
void a_print(const char *str) { cout << str << endl; }
};
class B: virtual A {
public:
void b_print() { a_print("B"); }
};
class C: virtual A, public B {
public:
void c_print() { a_print("C"); }
};
int main() {
C c;
c.a_print("A"); // Doesn't work
c.b_print();
c.c_print();
}
Вот ошибка компиляции.
test.cpp: In function ‘int main()’:
test.cpp:6: error: ‘void A::a_print(const char*)’ is inaccessible
test.cpp:21: error: within this context
test.cpp:21: error: ‘A’ is not an accessible base of ‘C’