我在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 )应该是一个很好的阅读。 –