我在Visual C++編寫的小程序++ 2010繼承功能inaccessable在C++
這是基類的代碼:
class BaseInfo {
private:
std::map <std::string, std::string> info;
std::vector<std::string> extra_info_key;
public:
uint get_id();
//Other function is hidden
};
uint BaseInfo::get_id() {
return (uint)atoi ((info["ID"]).c_str());
}
然後我做一個派生類,它宣稱爲:
class test:BaseInfo {
public:
void f();
};
void test::f (test& inf) {
cout<<inf.get_id()<<endl;
}
但我得到了一個錯誤:
function "BaseInfo::get_id is inaccessible.
我很困惑,似乎所有的都在C++規則中。
可我建議使用一些更多的空間用於可讀性 – sehe
[什麼是訪問符?我應該繼承與私人,保護或公共?](http://stackoverflow.com/questions/5447498/what-are-access-specifiers-should-i-inherit-with-private-protected-or-public/%5d )應該是一個很好的閱讀。 –