Click here to Skip to main content
15,917,608 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: template question Pin
Steve Messer9-Oct-03 21:11
Steve Messer9-Oct-03 21:11 
GeneralRe: template question Pin
Joaquín M López Muñoz9-Oct-03 21:23
Joaquín M López Muñoz9-Oct-03 21:23 
GeneralRe: template question Pin
Steve Messer9-Oct-03 21:30
Steve Messer9-Oct-03 21:30 
GeneralRe: template question Pin
Steve Messer9-Oct-03 21:08
Steve Messer9-Oct-03 21:08 
GeneralStrange things with parameters. Pin
esepich9-Oct-03 19:10
esepich9-Oct-03 19:10 
GeneralRe: Strange things with parameters. Pin
Anand Paranjpe9-Oct-03 19:52
Anand Paranjpe9-Oct-03 19:52 
GeneralDefine triangle class Pin
Anonymous9-Oct-03 18:40
Anonymous9-Oct-03 18:40 
GeneralRe: Define triangle class Pin
W. Hammer -sledge-11-Oct-03 9:29
W. Hammer -sledge-11-Oct-03 9:29 
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
GeneralHello &#213;&#226;&#202;&#199;&#202;&#178;&#195;&#180;&#209;&#189;&#163;&#191; Pin
hy_huangh9-Oct-03 18:36
hy_huangh9-Oct-03 18:36 
GeneralRe: Hello ÕâÊÇʲôѽ£¿ Pin
David Stone9-Oct-03 18:56
sitebuilderDavid Stone9-Oct-03 18:56 
GeneralFloating point calculation Pin
act_x9-Oct-03 18:20
act_x9-Oct-03 18:20 
GeneralRe: Floating point calculation Pin
Anand Paranjpe9-Oct-03 20:05
Anand Paranjpe9-Oct-03 20:05 
GeneralRe: Floating point calculation Pin
Anthony_Yio10-Oct-03 1:09
Anthony_Yio10-Oct-03 1:09 
GeneralRe: Floating point calculation Pin
JWood10-Oct-03 9:59
JWood10-Oct-03 9:59 
QuestionXML parsing with DOM?? Pin
xxhimanshu9-Oct-03 17:45
xxhimanshu9-Oct-03 17:45 
AnswerRe: XML parsing with DOM?? Pin
act_x9-Oct-03 18:28
act_x9-Oct-03 18:28 
AnswerRe: XML parsing with DOM?? Pin
Anand Paranjpe9-Oct-03 20:09
Anand Paranjpe9-Oct-03 20:09 
AnswerRe: XML parsing with DOM?? Pin
Ravi Bhavnani10-Oct-03 3:25
professionalRavi Bhavnani10-Oct-03 3:25 
Questionwhat does this mean? Pin
FlyingDancer9-Oct-03 17:34
FlyingDancer9-Oct-03 17:34 
AnswerRe: what does this mean? Pin
Anand Paranjpe9-Oct-03 20:15
Anand Paranjpe9-Oct-03 20:15 
GeneralRe: what does this mean? Pin
FlyingDancer9-Oct-03 21:26
FlyingDancer9-Oct-03 21:26 
GeneralRe: what does this mean? Pin
David Crow10-Oct-03 6:02
David Crow10-Oct-03 6:02 
GeneralRe: what does this mean? Pin
FlyingDancer12-Oct-03 3:31
FlyingDancer12-Oct-03 3:31 
GeneralMutex Objects, Semaphore Objects and Critical Section Objects Pin
FlyingDancer9-Oct-03 17:23
FlyingDancer9-Oct-03 17:23 
GeneralRe: Mutex Objects, Semaphore Objects and Critical Section Objects Pin
Anand Paranjpe9-Oct-03 20:20
Anand Paranjpe9-Oct-03 20:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.