consider follow simple code:
class Base {
protected:
int m_nAddr;
public:
Base(int addr_): m_nAddr(addr_) {}
virtual ~Base() {}
virtual int GetData() const = 0;
};
class KeyInfo: virtual public Base {
protected:
int m_nKey;
public:
KeyInfo(int addr_, int key_): Base(addr_), m_nKey(key_) {}
int GetData() const {
return m_nKey;
}
};
class AlgInfo: virtual public Base {
protected:
int m_nAlg;
public:
AlgInfo(int addr_, int alg_): Base(addr_), m_nAlg(alg) {}
void GetData() const {
return m_nAlg;
}
};
class PairInfo: public KeyInfo, public AlgInfo {
protected:
int m_nPair;
public:
PairInfo(int addr_, int key_, int alg_, int pair_)
: Base(addr_), KeyInfo(addr_, key_), AlgInfo(addr_, alg_),
m_nPair(pair_) {}
void GetData() const {
return m_nPair;
}
};
Q1. When an PairInfo is created, before its constructor PairInfo()
called, compiler will call Base(), KeyInfo() & AlgInfo, in which order
these 3 constructor will be called ?
Q2. As it is virtual inheritance, PairInfo only have a copy of Base,
so when constructor KeyInfo() and AlgInfo() are called, they will not
call their own parent class constructor Base() ?