Here is the starting code. The question is : How would you define OR make a method call from overcraft class to produce a BEEP !
class Vehicle {
public:
virtual void honk() = 0;
};
class Car : public Vehicle {
public:
void honk() { cout << "Beep!"; }
};
class Boat : public Vehicle {
public:
void honk() { cout << "Toot!"; }
};
class Hovercraft : public Car, public Boat {
public:
// ...
};
And here are the potentials solutions given to me : (it can be 1 to all answers possible)
-
Add using Hovercraft::Car::honk; at a global level of the program or in the function where we want it to make the call
-
add using Car::honk; in Hovercraft class
-
add using Car::honk(); in Hovercraft class
-
Car* c(new Hovercraft()); c->honk(); delete c;
-
Hovercraft h; h.Car::honk();
-
Hovercraft h; Car::h.honk();
-
There is nothing to do, the inheritance order is anyway car::honk() called when we do honk() call from hovercraft
-
Define in Overcraft a honk() method who call car::honk()
To me... 3 and 6 are false anyway. Am I right? I would pick 2 and 5 but when I submit these choices, the question is failed. I can try as much as I want but I would like to understand rather to try every combination...
Sorry for the translation mistake. Hope you will teach me some.
Aucun commentaire:
Enregistrer un commentaire