954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Last CLASS method needs help... PAIR::area()

Been working on this project for last 2 nights. Cant get rid of this error message on my last method PAIR::area() . It's defined at the bottom of my program.

Everything else compiles... builds... executes just fine. Rusty on the basics and trying to figure out methods.... here is my error message:

error C2601: 'area' : local function definitions are illegal
Error executing cl.exe.

It sounds obvious but I think I'm just a little blurry eyed. Project is due tonight (Thur) at 6pm. I think I need to go start at chapter one again It's has to be something dumb I'm doing.

Any help appreciated.

class PAIR
 
{private:
 int a;
 int b;
 
public:
 
 void print();
 PAIR();
 PAIR(int);
 PAIR(int,int);
 ~PAIR();

 void swap();
 int diff();
 int big();
 int area();
};

int main()
{
PAIR c, d(2), e(12,13);

int ans;
c.print();
d.print();
e.print();


d.swap();
d.print();
e.swap();
e.print();

ans = c.diff();
cout << "\nThe answer to c.diff() is  " << ans << endl;

int big = e.big () ;
cout << "\nThe larger number of e.big() is  " << big << endl << endl;

return 0;
}

PAIR::PAIR() 
{
a = 2;
b = 3;
}

void PAIR::print()
{cout << a << " " << b << endl;}

PAIR:: ~PAIR()
{
  cout << "Display Destructor Message" << endl;
}

PAIR::PAIR(int p1)
{a=p1;
b=p1;}

PAIR::PAIR(int p1,int p2)
{
a=p1;
b=p2;
}

void PAIR::swap()
{
 int c;
 c=a;
 a=b;
 b=c;
}

int PAIR::diff()
{
	return b - a;
}

int PAIR::big()
{
    if (a > b)
    {
        return a;
    }
    else 
    {
        return b;
    }

int PAIR::area()
    { 
                int z;
	z=(a*b);
		
    {
	return z;
    }
}
    
}
ToySoldier
Newbie Poster
20 posts since Oct 2005
Reputation Points: 18
Solved Threads: 0
 

.

class PAIR
 
{private:
 int a;
 int b;
 
public:
 
 void print();
 PAIR();
 PAIR(int);
 PAIR(int,int);
 ~PAIR();

 void swap();
 int diff();
 int big();
 int area();
};

int main()
{
PAIR c, d(2), e(12,13);

int ans;
c.print();
d.print();
e.print();


d.swap();
d.print();
e.swap();
e.print();

ans = c.diff();
cout << "\nThe answer to c.diff() is  " << ans << endl;

int big = e.big () ;
cout << "\nThe larger number of e.big() is  " << big << endl << endl;

return 0;
}

PAIR::PAIR() 
{
a = 2;
b = 3;
}

void PAIR::print()
{cout << a << " " << b << endl;}

PAIR:: ~PAIR()
{
  cout << "Display Destructor Message" << endl;
}

PAIR::PAIR(int p1)
{a=p1;
b=p1;}

PAIR::PAIR(int p1,int p2)
{
a=p1;
b=p2;
}

void PAIR::swap()
{
 int c;
 c=a;
 a=b;
 b=c;
}

int PAIR::diff()
{
    return b - a;
}

int PAIR::big()
{
    if (a > b)
    {
        return a;
    }
    else 
    {
        return b;
    }
} // this was missing

int PAIR::area()
    { 
                int z;
    z=(a*b);
        
    {
    return z;
    }
}
    
// } 
// this is extra brace

The things marked in red by me are the culprits. WHy dont u format the code properly so that typographic errors will be minimised. Do you write your code in Notepad. If so grab your self a syntax highlighter code editor which makes automatically proper indentations like Code::BLocks or Dev Bloodshed.

The links for the above IDE can be found at teh top of this forum in the thread named "Starting C".

Hope it helped, bye.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

Thanks... cleaned it up and turned it in.

Gonna take my time with our next program.

ToySoldier
Newbie Poster
20 posts since Oct 2005
Reputation Points: 18
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You