I cannot understand why I am getting an error for 'nameInput' and 'weightInput' on Line 15 in Pitcher.cpp. I am simply trying to create a "PITCHER" class derived from the "PLAYER" class.
I have been over this problem for hours, comparing it to similar code, and simply do not get it. I have not even got to writing the main function yet or filled in some of the functions because this problem is holding me up. Any help would be much appreciated.
// PLAYER.H FILE
// Specification File for Player Class
#ifndef PLAYER_H
#define PLAYER_H
#include<string> // string class included for name of Player
usingnamespace std; // needed for string
class Player
{
private:
string name;
int weight;
public:
Player(); //Default Constructor
Player(string, int); //Constructor to set name and weight
//Function prototypes
void show(); //Show method to print name and weight
};
#endif
// PITCHER.H FILE
#ifndef PITCHER_H
#define PITCHER_H
#include "Player.h"
class Pitcher : public Player
{
protected:
int earnedRuns;
int inningsPitched;
public:
Pitcher(); // Default Constructor
Pitcher(int runs, int innings); // Constructor #2
//Function prototypes
float eraCalc(int, int); // Earned run average calc function
void show(); //Show method to print earnedRuns, inningsPitched, and calculated ERA
};
#endif
Thanks FurryGuy. If I change the prototype, then the actual definition in the cpp file looks like it needs to change as well, which is confusing, because the order of the prototype is:
Pitcher(int, int, string, int); // Constructor #2
and the first line of the definition is:
Pitcher::Pitcher(int runs, int innings) : Player(nameInput, weightInput)
That worked! I believe that I was thinking that the function parameter DID already match, because the 4 used variables were listed already, albeit split between the Pitcher and the Player.
Which makes me wonder: If the Pitcher already has all 4 of the used variables, what is the significance/point of the " : Player(nameInput, weightInput)" at the end?
Which makes me wonder: If the Pitcher already has all 4 of the used variables, what is the significance/point of the " : Player(nameInput, weightInput)" at the end?
Because Pitcher is a derived class from Player, that bit of code constructs a Player object when it constructs the Pitcher object.