我有Point
一个具有X
,Y
和Name
作为数据成员的类。我超载了
T operator-(const Point<T> &);
这会计算两点之间的距离并返回一个值
template < typename T>
T Point<T>::operator-(const Point<T> &rhs)
{
cout << "\nThe distance between " << getName() << " and "
<< rhs.getName() << " = ";
return sqrt(pow(rhs.getX() - getX(), 2) + pow(rhs.getY() - getY(), 2));;
}
main
功能_
int main () {
Point<double> P1(3.0, 4.1, "Point 1");
Point<double> P2(6.4, 2.9, "Point 2");
cout << P2 - P1;
return EXIT_SUCCESS;
}
但问题是这个程序没有编译,我收到这个错误:
Undefined symbols:
"Point<double>::operator-(Point<double>&)", referenced from:
_main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
任何帮助表示赞赏...