.hpp文件是对.h文件做的补充和解析,两个文件要一起使用,通常调用的时候包含.hpp文件,.hpp文件包含.h文件
//template.h
#pragma once
#include<stdlib.h>
#include<iostream>
using namespace std;
template <typename T>
class Complex
{
public:
friend ostream& operator<<<T>(ostream &out, Complex &c3);
Complex(T a = 0, T b = 0);
void PrintfComplex();
Complex operator+(Complex &c);
Complex operator-(Complex &c);
private:
T a;
T b;
};
//template.hpp
#include<stdlib.h>
#include<math.h>
#include<iostream>
using namespace std;
#include "template.h"
template <typename T>
Complex<T>::Complex(T a = 0, T b = 0)
{
this->a = a;
this->b = b;
}
template <typename T>
void Complex<T>::PrintfComplex()
{
if (b >= 0)
cout << a << " + " << b << "i