c++ - Derived Class cannot access Parent class method -


i getting error "class derived has no member named 'getx'" when try compile code this:

class base {     public:         int getx() {return x};     protected:         int x;  };     class derived : public base {     public:         void myfunction(){int y = getx()};  }; 

i contrived example clarify, because got lot of errors when derived class tries use methods parent class should have inherited. have tried using 'this' keyword before method invocation, did not work either. help.

correcting code

class base {     public:         int getx() {return x; }     protected:         int x;  };     class derived : public base {     public:         int myfunction(){int y = getx(); return y; }  }; 

compiles me with

g++ -c -o /dev/null -wall derive.c 

.


Comments