'util.h'中定义的以下代码编译和链接.但是,当我将运算符重载的实现移动到'util.cc'时,链接器无法解析符号.这可能是这样做,还是由于模板的性质而无法做到这一点?
谢谢,
util.h
template<class T>
struct Rect {
T x, y, w, h;
friend bool operator ==(const Rect<T> &a, const Rect<T> &b) {
return (a.x == b.x && a.y == b.y && a.w == b.w && a.h == b.h);
}
friend bool operator !=(const Rect<T> &a, const Rect<T> &b) {
return !(a == b);
}
};
Run Code Online (Sandbox Code Playgroud)
util.h
template<class T>
struct Rect {
T x, y, w, h;
friend bool operator ==(const Rect<T> &a, const Rect<T> &b);
friend bool …Run Code Online (Sandbox Code Playgroud)