What's Wrong with these code?

R

Richard

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(8);
Sally.SetSalary(40000);

cout << "John is " << John.GetAge << " years old and he has been with";
cout << " the firm for " << John.GetYearsOfService << " years\n";
cout << "John earns $" << John.GetSalary << " dollars a year.\n\n";

cout << "Sally is " << Sally.GetAge << "years old and she has been with";
cout << " the firm for " << Sally.GetYearsOfService << " years\n";
cout << "Sally earns $" << Sally.GetSalary << " dollars a year\n\n";
}

What's wrong?

Thanks!
 
P

Peter van Merkerk

Richard said:
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(8);
Sally.SetSalary(40000);

cout << "John is " << John.GetAge << " years old and he has been with";
cout << " the firm for " << John.GetYearsOfService << " years\n";
cout << "John earns $" << John.GetSalary << " dollars a year.\n\n";

cout << "Sally is " << Sally.GetAge << "years old and she has been with";
cout << " the firm for " << Sally.GetYearsOfService << " years\n";
cout << "Sally earns $" << Sally.GetSalary << " dollars a year\n\n";
}

What's wrong?

You forgot the brackets () after the John.GetAge,
John.GetYearsOfService...etc.
 
T

Tim Love

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<iostream>
if your set-up allows it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top