Here's my class structure:
class Parent {
public:
void foo(); // foo() defined in superclass
};
class Child : public Parent {
private:
int bar;
public:
Child(int);
int getBar();
};
Child::Child(int b) {
bar = b;
}
void Child::foo() { // foo() implemented in subclass
std::cout << getBar() << std::endl;
}
g++ gives me an error that foo()
is not within Child
scope, and changing it to void Parent::foo()
, I'm left with an error that getBar()
is not within Parent
scope.
I'm aware of virtual functions but I do not want to define foo()
in Child
, only implement it.
How do I gain method visibility within Child
of the Parent
method foo()
?
My thought process is the line class Child : public Parent
means Child
inherits member methods of Parent
, thus Child
should be able to see foo()
.