-
class definition Q
I am trying to constuct a class that will represent an employee. I believe my declaration matches the definition of the constructor. Why am I getting the below errors? why would they be invalid function declarations?
Code:
#include <iostream>
#include <iomanip>
using namespace std;
//class declaration
class Employee
{
private:
int idNum;
float payRate;
int maxHours;
public:
Employee (int = 45, float = 9.00, int = 40);
void changeData (int, float, int);
void displayData (int, float, int);
};
//class implementation section
Employee : : Employee (int id, float rate, int max) //unqualified-id before':' token
{
idNum = id;
payrate = rate;
maxhours = max;
}
void Employee : : changeData (int id, float rate, int max) //invalid function declaration
{
idNum = id;
payRate = rate;
maxHours = max;
return;
}
void Employee : : displayData() ////invalid function declaration
{
cout<< "The employee ID is ";
cout<< idNum << '/'
<< "The employee pay is ";
<< payRate << '/'
<< "The employee maximum hours are ";
<< maxHours << '/'
<< endl;
return;
-
I am not 100% sure, but try taking the space out from between the two colons... '::' instead of ': :'
-
yeah, I already tried this and in numerous ways! lol
tks!!
-
ok, just tried it again to double check myself and I now have 6 errors instead of 3...so, I am sure that is not the problem...
-
Everything else looks ok, What other errors did it bring up?
-
The language is case-sensitive: payrate is not the same as payRate, maxhours is not the same as maxHours.
Function signatures are important:
Code:
void displayData (int, float, int);
does not match
Code:
void Employee :: displayData() ////invalid function declaration
-
Dang, I must need some sleep... did not even see that myself.....
-
And if you're going to break things into multiple lines, don't prematurely end the lines.
Code:
void Employee :: displayData(int idNum, float payRate, int maxHours)
{
cout<< "The employee ID is ";
cout<< idNum << '/'
<< "The employee pay is ";
<< payRate << '/'
<< "The employee maximum hours are ";
<< maxHours << '/'
<< endl;
return;
}
-
yeah, it 'tis a bit late....
well I changed the case sensitive items (can't believe I missed those) and I will work on the functions. Back to more reading! Thanks !! ;)