PDA

Click to See Complete Forum and Search --> : Hye i am still getting around 31 errors on this Simple Class! whats up?


struntz
Feb 12th, 2001, 08:07 PM
Hello everyone again, i still can't figure out this problem!
i am getting these compiler errors!


here is my .hpp file with the class interface:


#include <iostream.h>

class Employee
{
public:
void SetAge(int EAge);
void SetyearsOfService(int yOf);
void SetSalary(int Money);

int GetAge();
int GetyearsOfservice();
int GetSalary();


private:
int age;
int yearsOfservice;
int Salary;

};


here is the .cpp file with the implemnation of the class methods:

#include "Employee.hpp"

//function implamenation (can't spell) :P
void Cat::SetAge(int EAge)
{
age = EAge;
}
//
void Cat::SetyearsOfService(int yOf)
{
yearsOfservice = yOf; //
}
void Cat::SetSalary(int Money) //
{
Salary = Money;
}

int Cat::GetAge()
{
return age;
} //

int Cat::GetyearsOfservice() //
{
return yearsOfservice;
}

int Cat::GetSalary()
{
return Salary;
}

int main() {

Employee Cory;
Cory.SetAge(15);
Cory.SetSalary(100000);
Cory.GetyearsOfservice(4);

cout << Cory.GetAge << endl;
cout << Cory.GetSalary << endl;
cout << Cory.GetyearsOfservice << endl;
return 0;
}


and if u want the full list of errors, i'll post it in the next message! :D

thanks for listening

Cybrg641
Feb 12th, 2001, 08:12 PM
replace the "Cat" with "Employee" for each of the functions used in the class. And when you are calling some of the functions, you are passing parameters to them when it they have none.

struntz
Feb 12th, 2001, 08:26 PM
hah i can't belive i put Cat insteed of employee, anyways..i fixed that, i still got 31 errors..and what do u mean what fucntions did i write which shoudln't have any paremeters passed ?

Cybrg641
Feb 12th, 2001, 08:34 PM
Sorry, I should have been more specific. In your code, you put...


Cory.GetyearsOfservice(4);


but when you declared it, you didn't have any parameters.
Also, you need to add a parenthesis at the end of every function. So replace...


cout << Cory.GetAge << endl;
cout << Cory.GetSalary << endl;
cout << Cory.GetyearsOfservice << endl;
return 0;


with...


cout << Cory.GetAge() << endl;
cout << Cory.GetSalary() << endl;
cout << Cory.GetyearsOfservice() << endl;
return 0;

struntz
Feb 12th, 2001, 08:41 PM
thanks that and a typo of a variable fixed everything!

parksie
Feb 14th, 2001, 09:19 AM
In your .hpp file I would suggest putting some protection against multiple-inclusion into it, such as:

#ifndef __EMPLOYEE_HPP__
#define __EMPLOYEE_HPP__

// Code here

#endif


Otherwise if you include the file from two other source files the linker (I think) will choke :(