I'm currently learning about class inheritance and constructors and I can't seem to figure how to get the base class' overloaded constructor to fire from the derived class.
/*
* ProductionWorker.h
*
* Created on: Oct 8, 2011
* Author: Chris Hayes
*/
#ifndef PRODUCTIONWORKER_H_
#define PRODUCTIONWORKER_H_
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <limits>
#include "Employee.h"
usingnamespace std;
class ProductionWorker : public Employee
{
public:
ProductionWorker();
ProductionWorker(int inShift, double payRate)
: Employee(name, number, date){};
virtual ~ProductionWorker();
bool setShift(int inShift);
int getShift() const;
void printProductionWorker() const;
protected:
int *shift;
double *hourlyPayRate;
};
#endif /* PRODUCTIONWORKER_H_ */
and implementation of the constructor I am trying to get to fire:
1 2 3 4 5 6 7 8 9 10
ProductionWorker::ProductionWorker(string name, int number, Date date, int inShift, double payRate)
: Employee(name, number, date)
{
shift = newint;
hourlyPayRate = newdouble;
setShift(inShift);
*hourlyPayRate = payRate;
}
and here is the console output when I try to build:
1 2 3
../ProductionWorker.h:26: error: 'name' was not declared in this scope
../ProductionWorker.h:26: error: 'number' was not declared in this scope
../ProductionWorker.h:26: error: 'date' was not declared in this scope
Any help would be greatly appreciated. I feel like it is something super simple but I've been trying to figure it out for hours and looked all over on the internet for an answer. Thanks in advance for any help provided.
ProductionWorker(string name, int number, Date date, int inShift, double payRate)
: Employee(name, number, date){};
and I get these errors now:
[code]
../ProductionWorker.cpp:23: error: redefinition of 'ProductionWorker::ProductionWorker(std::string, int, Date, int, double)'
../ProductionWorker.h:25: error: 'ProductionWorker::ProductionWorker(std::string, int, Date, int, double)' previously defined here
[\code]
wow...like I said, I knew it would be simple. I just realized it was because in the header file I only needed to have
[code]
ProductionWorker(string name, int number, Date date, int inShift, double payRate);
[\code]
when I had
[code]
ProductionWorker(int inShift, double payRate)
: Employee(name, number, date){};
[\code]
I can't believe it was that simple. Oh and I had tried previously adding in the arguments like you suggest LBEaston but had gotten the above errors which made me think it was incorrect to add those arguments. Thanks for the help. Once I took a break came back to it and added those back it, I quickly saw my error.