1

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;
    }
}
    
}
2
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by ToySoldier
1

.

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.

0

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

Gonna take my time with our next program.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.