I'm in an intro to C++ class and I'm trying to find out why I'm getting a "no matching function for call" error. And I've looked through other posts, but those mainly seem to be problems with the constructors themselves.
This is simplified snippets:
In Base Class - Ship
// Members: shipName, shipBuiltYear
Ship::Ship(){ //implementation }
Ship::Ship(string name, string year){ //implementation }
void Ship::set(string name, string year){ //implementation }
In Derived Class - PirateShip
// Members: numPirates
PirateShip::PirateShip() : Ship() { //implementation }
PirateShip::PirateShip(string name, string year, string pirates) : ship(name, year){ //implementation }
void PirateShip::set(int pirates){ //implementation }
In main
Ship *ships[2] = {new Ship(), new PirateShip()};
ships[0] -> set("Luvinia", "2020"); // using setter from base class
ships[1] -> set("Skylin", "2030"); // using setter from base class
ships[1] -> set(100); // using setter from derived class
Is the problem that you can't use the base class to set the PirateShip, then use the PirateShip to set it again?
Do I have to change:
void PirateShip::set(int pirates){ //implementation }
to:
void PirateShip::set(string name, string year, string pirates)
{
Ship::set(name, year);
numPirates = pirates;
}
?
Or is there another way to do this?