类模板,函数模板,请问这段代码为什么出错,谢谢大侠们指教!
#include<iostream>template<classT1,classT2>classTwoThings{T1thing1;T2thing2;public:Tw...
#include<iostream>
template<class T1,class T2>
class TwoThings{
T1 thing1;
T2 thing2;
public:
TwoThings(T1 t1,T2 t2):thing1(t1),thing2(t2){}
template<class T3,class T4>
friend std::ostream& operator<< (std::ostream& os, const TwoThings<T3,T4>&);
};
template<class T1,class T2>
std::ostream& operator<< (std::ostream& os, const TwoThings<T1,T2>& tt){
std::cout<<tt.thing1<<' '<<tt.thing2<<std::endl;
return os;
}
int main(){
int a=123;
int b=456.789;
TwoThings<int,double> my_twothings(a,b);
std::cout<<my_twothings;
return 1;
} 展开
template<class T1,class T2>
class TwoThings{
T1 thing1;
T2 thing2;
public:
TwoThings(T1 t1,T2 t2):thing1(t1),thing2(t2){}
template<class T3,class T4>
friend std::ostream& operator<< (std::ostream& os, const TwoThings<T3,T4>&);
};
template<class T1,class T2>
std::ostream& operator<< (std::ostream& os, const TwoThings<T1,T2>& tt){
std::cout<<tt.thing1<<' '<<tt.thing2<<std::endl;
return os;
}
int main(){
int a=123;
int b=456.789;
TwoThings<int,double> my_twothings(a,b);
std::cout<<my_twothings;
return 1;
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询