#include <iostream>
using namespace std;
class base{
public:
int i;
base(){
i=1;
cout<<"Base Constructor";
}
};
class derived: private base{
public:
derived(){
i=2;
cout<<"Derived constructor";
}
};
int main(){
derived c;
return 0;
}
對於上面的代碼,爲什麼我會得到輸出爲 「Base ConstructorDerived Constructor」 即使我繼承使用私有?我繼承了使用私人的構造函數,爲什麼我仍然可以從主函數訪問它?
你期望什麼? – 2013-02-23 16:47:17
只能派生構造函數 – Alex 2013-02-23 16:47:54