C++ 弱问一个# Programming - 葵花宝典
m*o
1 楼
请问这个继承最后输出的怎么是BB,而不是CC呢?main函数里的逻辑过程是什么样的?
#include
using namespace std;
class A{
protected:
virtual void print() { cout << "A" << endl; }
void print2() { cout << "AA" << endl; }
};
class B {
public:
virtual void print() { cout << "B" << endl; }
void print2() { cout << "BB" << endl; }
};
class C : public A, public B{
public:
void print2() { cout << "CC" << endl; }
};
int main()
{
C c;
B* p = &c;
p->print2();
};
#include
using namespace std;
class A{
protected:
virtual void print() { cout << "A" << endl; }
void print2() { cout << "AA" << endl; }
};
class B {
public:
virtual void print() { cout << "B" << endl; }
void print2() { cout << "BB" << endl; }
};
class C : public A, public B{
public:
void print2() { cout << "CC" << endl; }
};
int main()
{
C c;
B* p = &c;
p->print2();
};