Maybe it's a weird question -sorry if the title is confusing- ...this is the code:
#include <iostream>
class Inherited {
public:
int method1() {
int value = 2;
return value;
}
int method2() {
int value = method1() + 3;
return value;
}
};
class Inheriting : public Inherited {
public:
int method1() {
int value = 3;
return value;
}
};
int main(){
Inheriting object;
std::cout << "method1 value = " << object.method1() << "\n";
std::cout << "method2 value = " << object.method2() << "\n";
return 0;
}
and it's output:
method1 value = 3
method2 value = 5
So, Is there any way that method2 can use method1 from the inheriting class -and it's value could be 6 instead 5- or must I overload the two methods in the inheriting class? It seems that virtual methods may be the solution, but I can't see exactly how. Very grateful for any help.