C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

What's Wrong with these code?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Richard
Guest





PostPosted: Tue Sep 28, 2004 10:45 am    Post subject: What's Wrong with these code? Reply with 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<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(Cool;
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





PostPosted: Tue Sep 28, 2004 10:48 am    Post subject: Re: What's Wrong with these code? Reply with quote



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(Cool;
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





PostPosted: Tue Sep 28, 2004 10:54 am    Post subject: Re: What's Wrong with these code? Reply with quote



[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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.