0
我有關於虛擬繼承的問題。 我很感興趣,爲什麼這個代碼打印1000(從類「兩節」),而不是3(從類「一」)虛擬公共繼承?需要幫助瞭解代碼
下面的代碼:
#include <iostream>
using namespace std;
class A {
protected:
int number;
public:
A (int a=0) {number=a;}
};
class one:virtual public A {
public:
one (int a=3) {number=a;}
void print() {cout<<number<<endl;}
};
class two :virtual public A {
public:
two (int a=1000) {number =a;}
void print() { cout<<number<<endl; }
};
class B:public one,public two {
public:
void print() { cout<<number<<endl; }
};
int main() {
B A;
A.print();
}