作者x3795566 (冀忆)
看板C_and_CPP
标题[问题] template+operator overloading的问题
时间Thu Mar 19 22:54:59 2009
假设我有一个结构为A 一个class为test
然後在main中 我宣告了两个物件temp1,temp2
test<float> temp1;
test<A> temp2;
然後我欲使temp1+temp2 所以打算多载运算子
而有下面程式码(只贴定义部份)
template <class T>
float test<T>::operator+(test& i)
{
.
.
.
}
编译结果显示错误
no match for 'operator+' in 'temp1 + temp2'
candidates are: float test<T>::operator+(test<T>&) [with T = float]
我的编译器为Dev-C++
我有试着将test<A> temp2 改为 test<float> temp2
编译就成功了 所以我想问题在於operator+(test& i)的传入参数型态
不知道高手可以告知我那边的型态要如何写呢? 感谢<(_ _)>
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.117.194.90
1F:推 ADF:float template<class T,class T1> test<T>::operator+ 03/19 23:04
2F:→ ADF:(test<T1>& t){ ....................} 03/19 23:04
3F:→ x3795566:不是很懂楼上打的说~"~ 03/20 00:06