| View previous topic :: View next topic |
| Author |
Message |
Richard Guest
|
Posted: Tue Sep 28, 2004 10:45 am Post subject: What's Wrong with these code? |
|
|
I get this error message:
Error E2235 EX3.CPP 60: Member function must be called or its address taken in
function main()
From these code:
#include<iostream.h>
class Employee {
public:
int GetAge();
void SetAge(int age);
int GetYearsOfService();
void SetYearsOfService(int yearsOfService);
int GetSalary();
void SetSalary(int Salary);
private:
int myage;
int myyearsOfService;
int mySalary;
};
int Employee::GetAge()
{
return myage;
}
void Employee::SetAge(int age)
{
myage = age;
}
int Employee::GetYearsOfService()
{
return myyearsOfService;
}
void Employee::SetYearsOfService(int yearsOfService)
{
myyearsOfService = yearsOfService;
}
int Employee::GetSalary()
{
return mySalary;
}
void Employee::SetSalary(int Salary)
{
mySalary = Salary;
}
void main (void)
{
Employee John;
Employee Sally;
John.SetAge(30);
John.SetYearsOfService(5);
John.SetSalary(50000);
Sally.SetAge(32);
Sally.SetYearsOfService( ;
Sally.SetSalary(40000);
cout << "John is " << John.GetAge << " years old and he has been with";
cout << " the firm for " << John.GetYearsOfService << " yearsn";
cout << "John earns $" << John.GetSalary << " dollars a year.nn";
cout << "Sally is " << Sally.GetAge << "years old and she has been with";
cout << " the firm for " << Sally.GetYearsOfService << " yearsn";
cout << "Sally earns $" << Sally.GetSalary << " dollars a yearnn";
}
What's wrong?
Thanks!
|
|
| Back to top |
|
 |
Peter van Merkerk Guest
|
Posted: Tue Sep 28, 2004 10:48 am Post subject: Re: What's Wrong with these code? |
|
|
Richard wrote:
| Quote: | I get this error message:
Error E2235 EX3.CPP 60: Member function must be called or its address taken in
function main()
From these code:
#include
class Employee {
public:
int GetAge();
void SetAge(int age);
int GetYearsOfService();
void SetYearsOfService(int yearsOfService);
int GetSalary();
void SetSalary(int Salary);
private:
int myage;
int myyearsOfService;
int mySalary;
};
int Employee::GetAge()
{
return myage;
}
void Employee::SetAge(int age)
{
myage = age;
}
int Employee::GetYearsOfService()
{
return myyearsOfService;
}
void Employee::SetYearsOfService(int yearsOfService)
{
myyearsOfService = yearsOfService;
}
int Employee::GetSalary()
{
return mySalary;
}
void Employee::SetSalary(int Salary)
{
mySalary = Salary;
}
void main (void)
{
Employee John;
Employee Sally;
John.SetAge(30);
John.SetYearsOfService(5);
John.SetSalary(50000);
Sally.SetAge(32);
Sally.SetYearsOfService( ;
Sally.SetSalary(40000);
cout << "John is " << John.GetAge << " years old and he has been with";
cout << " the firm for " << John.GetYearsOfService << " yearsn";
cout << "John earns $" << John.GetSalary << " dollars a year.nn";
cout << "Sally is " << Sally.GetAge << "years old and she has been with";
cout << " the firm for " << Sally.GetYearsOfService << " yearsn";
cout << "Sally earns $" << Sally.GetSalary << " dollars a yearnn";
}
What's wrong?
|
You forgot the brackets () after the John.GetAge,
John.GetYearsOfService...etc.
--
Peter van Merkerk
peter.van.merkerk(at)dse.nl
|
|
| Back to top |
|
 |
Tim Love Guest
|
Posted: Tue Sep 28, 2004 10:54 am Post subject: Re: What's Wrong with these code? |
|
|
[email]richard_kwan2 (AT) yahoo (DOT) com[/email] (Richard) writes:
| Quote: | I get this error message:
Error E2235 EX3.CPP 60: Member function must be called or its address taken in
...
cout << "John is " << John.GetAge << " years old and he has been with";
...
What's wrong?
When you call a fn that doesn't take args, you still need the (), so |
"John.GetAge" should be "John.GetAge()", etc.
Also main shouldn't return void. And try to use
#include
if your set-up allows it.
|
|
| Back to top |
|
 |
|