简体   繁体   中英

inherited function inaccessable in C++

I am writing a small program in Visual C++ 2010.

This is code of the base class:

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());
}

Then I make a derived class, which is announced as:

class test:BaseInfo {
public:
    void f();
};

void test::f (test& inf) {
    cout<<inf.get_id()<<endl;
}

But I got an error:

function "BaseInfo::get_id is inaccessible.

I am confused, it seems all is in the c++ rules.

You're using private inheritance, that's why. Change:

class test : BaseInfo

to:

class test : public BaseInfo

For more info about public, protected and private inheritance, look here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM