home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C++ for Dummies (3rd Edition)
/
C_FD.iso
/
CHAP26
/
CHAP26_1.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-09-02
|
708b
|
47 lines
// Chap26_1.cpp
#include <math.h>
template <class T>
T max(T& tX1, T& tX2)
{
T tX = tX1;
if (tX < tX2)
{
tX = tX2;
}
return tX;
}
// Complex - this is a minimal complex class
class Complex
{
protected:
double dReal, dImagine;
public:
Complex(double dR = 0, double dI = 0)
{
dReal = dR;
dImagine = dI;
}
double abs()
{
return sqrt(dReal * dReal +
dImagine * dImagine);
}
};
int operator < (Complex& c1, Complex& c2)
{
return c1.abs() < c2.abs();
}
int main()
{
Complex c1(2.0);
Complex c2(1.0);
Complex c3 = max(c1, c2);
return 0;
}