0

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.

sehe
  • 374,641
  • 47
  • 450
  • 633
Bing Hsu
  • 692
  • 1
  • 8
  • 14
  • may I suggest using a few more spaces for legibility – sehe Oct 31 '11 at 15:34
  • [What are access specifiers? Should I inherit with private, protected or public?](http://stackoverflow.com/questions/5447498/what-are-access-specifiers-should-i-inherit-with-private-protected-or-public/%5d) Should be a good read. – Alok Save Oct 31 '11 at 15:37

1 Answers1

13

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

dario_ramos
  • 7,118
  • 9
  • 61
  • 108