OK, let me see, if i understood you correctly. You want to use an overloaded operator << . But what you have done, is only using the normal output of an float. The overloading would look like this:
ostream& operator<< (ostream& ostr, CTriangle& triangle)
{
ostr << "Side1 = " << triangle.side1 << endl
<< "Side2 = " << triangle.side2 << endl
<< "Side3 = " << triangle.side3 << endl;
return ostr;
}
The overloaded operator== looks like this:
bool operator ==(const CTriangle& tri1, const CTriangle& tri2)
{
if (tri1.side1 == tri2.side1
&& tri1.side2 == tri2.side2
&& tri1.side3 == tri2.side3)
return true;
else
return false;
}
My personal advice: You should divide your program into three files. ----------------------- First file - a file containing the declaration of the triangle class. Name this file triangle.h !! Remember that triangle is a class, so name the class CTriangle. !! ----------------------- Second file - Name this file triangle.cpp include your triangle.h by using #include "triangle.h"
Now put all the definitions of your CTriangle class in here (for instance yout get-functions etc. and the overloaded operators). Don't forget neccessary inclusions like iostream.h ----------------------- Third file - name this file main.cpp include your triangle.h by using
#include "triangle.h"
#include <iostream.h>
void main()
{
CTriangle triangle1, triangle2(5.0, 4.0, 3.0), triangle3(6.0, 4.0, 4.0);
cout << "Display triangle 1:\n";
cout << triangle1 ;
cout << "Display triangle 2:\n";
cout << triangle2 ;
cout << "Display triangle 3:\n";
cout << triangle3;
if (triangle2 == triangle3)
cout << "identical" << endl;
else
cout << "not identical" << endl;
<
}
I havent compiled it, but this should work. Test it by changing the values of the triangle2 and triangle3. Hope this helps sledge