adding functionality for function member

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.

How can i go about 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?


Augment the base classes output
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
using std::cout;

class first{
public:

    virtual int 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();
}


Change the value
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
using std::cout;

class first{
public:

    virtual int 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();
}


That about what you're looking for?
Topic archived. No new replies allowed.