What's wrong with my code??

#include<iostream>
using namespace std;

class RectangleType
{
private :

int length;
int width;
int perimeter;
int area;

public :

RectangleType compareArea(RectangleType ,RectangleType ) ;
RectangleType()
{

}
RectangleType(int x,int y)
{
length=x;
width=y;
}
void SetSize (int a,int b)
{
length=a;
width=b;
}
void PrintRectangle()
{
cout<<"Rectangle has length"<<length<<" and width "<<width<<endl;
}
int ReturnArea()
{
area=length*width;
return area;
}
int ReturnPerimeter()
{
perimeter=2*(length + width);
return perimeter;
}

};


RectangleType compareArea(RectangleType,RectangleType);
int main()
{

RectangleType aRectangle, bRectangle(2,6);
aRectangle.SetSize(10,5);
aRectangle.PrintRectangle();
cout<<"Area : " ;
cout<<aRectangle.ReturnArea()<<endl;
cout<<"Perimeter : ";
cout<<aRectangle.ReturnPerimeter()<<endl;
cout<<endl<<endl;
bRectangle=aRectangle;
cout<<"biggest area is : ";
compareArea(aRectangle,bRectangle);

bRectangle.PrintRectangle();
return 0;
}
RectangleType RectangleType::compareArea(RectangleType l,RectangleType k)
{
if (l.ReturnArea() == k.ReturnArea())
{
cout<<"Same area"<<endl;

}
else if (l.ReturnArea() < k.ReturnArea())
{
return k;
}
else if (l.ReturnArea() > k.ReturnArea())
{
return l;
}
}


dev compiler show this error : undefined reference to 'compareArea(RectangleType,RectangleType)'
HELP
You have not written the function compareArea. You have written the member function compareArea in the RectangleType class, but you're not calling it. You're trying to call some other function.

Class functions are called via an instance of that class, like this.

someRectangleTypeObjectThatYouMustMake.compareArea(aRectangle,bRectangle);
Last edited on
Yes i have written that function,is at the end. thanks for answering
RectangleType RectangleType::compareArea(RectangleType l,RectangleType k) i used this way to write the function and because it is outside the class it can be called just like this compareArea(aRectangle,bRectangle); in main. or i should use someRectangleTypeObjectThatYouMustMake.compareArea(aRectangle,bRectangle);
this? :(
Last edited on
well you're trying to declare CompareArea as a member of RectangleType, inside of the classes definition. So you could do with deleting compareArea in rectangleTypes definition and changing compareArea's type right before main to a char. Also dont forget to change CompareArea's type at the bottom.

[Edit] Oh wait your trying to return the class in that function... i dont actually know if thats possible(or necessary for that matter as your not using the return value in any way)
Last edited on
yes compareArea must return an object of the class
because it is outside the class it can be called just like this compareArea(aRectangle,bRectangle); in main.

It is not outside the class. Look at it; it has
RectangleType::
in it. Clearly, it is part of the class.

Last edited on
done,thank you very very much :))
Topic archived. No new replies allowed.