#include
創(chuàng)新互聯(lián)是專業(yè)的橋西網(wǎng)站建設(shè)公司,橋西接單;提供成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計,網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行橋西網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊,希望更多企業(yè)前來合作!
using namespace std;
template
class Complex{
public:
Complex(T a, T b);
void setComplex(T a,T b);
friend Complex
//對于模板類的友員函數(shù)一定要寫在類內(nèi)?。?!不可以再類外實(shí)現(xiàn)
T p_w_picpath = c1.p_w_picpath + c2.p_w_picpath;
T real = c1.real + c2.real;
return Complex
//這個必須按照這樣寫,不能加個對象!因?yàn)轭愋筒淮_定!
}
friend Complex
T p_w_picpath = c1.p_w_picpath - c2.p_w_picpath;
T real = c1.real - c2.real;
return Complex
}
friend Complex
return Complex
}
void print()const;
private:
T real, p_w_picpath;
};
template
Complex
setComplex(a, b);
}
template
void Complex
cout << "real=" << real << "p_w_picpath=" << p_w_picpath << endl;
}
template
void Complex
real = a;
p_w_picpath = b;
}
int main(){
Complex
Complex
(a + b).print();
(a - b).print();
(-a).print();
system("pause");
return 0;
}