I have a base class with int area () return a int value
I also have a subclass can adding functionality to this function and return a int value . However, there would be 2 return keywords . But i only want 1 after adding new things in it.
Well that depends on what you want to do, by adding functionality do you mean it appends the value of the base class's area function or it does something different entirely to get the area?
#include <iostream>
using std::cout;
class first{
public:
virtualint getval();
};
class second: public first{
public:
int getval();
};
int first::getval(){
return 5;
}
int second::getval(){
return 4 + first::getval();
}
int main(){
second sec;
cout << sec.getval();
}
#include <iostream>
using std::cout;
class first{
public:
virtualint getval();
};
class second: public first{
public:
int getval();
};
int first::getval(){
return 5;
}
int second::getval(){
return 4;
}
int main(){
second sec;
cout << sec.getval();
}