vendredi 2 septembre 2016

do I need a virtual function

I've a base class as follows -

Class Base {

    int a;
    int b;
    someInfo c;

  public:
    void setInfo(someInfo);
    someInfo getInfo();
};

with someInfo defined as -

struct someInfo{
    std::string name;
    std::string school;
};

Now I've a child class as follows:

Class child: public Base{

    int e;
    int f;
    someMoreInfo g;

  public:
    void setInfo(someMoreInfo);
    someMoreInfo getInfo();
};

with someMoreInfo struct as -

struct someMoreInfo{
    someInfo i;
    int j;
};

Now when implementing getInfo() and setInfo of the child class, do I need to make the base class's respective function virtual and override them here? Because everyone is saying so and I have got no idea why should I do that and why this wouldn't work already, since both are different set of functions, difference being in return value or that of parameter.

Any help for this fellow confused student would be appreciated :)

Aucun commentaire:

Enregistrer un commentaire