一个.h文件标准的结构:
- 前置声明
- 类声明
- 类定义
complex.h
#ifndef __COMPLEX__
#define __COMPLEX__
#include <cmath>
//前置声明
class ostream;
class complex;
complex&
__doapl (complex* ths, const complex& r);
//类声明
template<typename T>
class complex {
private:
T imaginary, real;
friend complex& __doapl (complex* , const complex &);
public:
complex (T r = 0,T i = 0)
: real(r), imaginary(i)
{ }
complex& operator += (const complex& );
T real () const { return real; }
T imaginary() const { return imaginary; }
};
//类定义
complex::
#endif