qq_41822833 2023-03-29 20:00 采纳率: 60%
浏览 20

函数模板重载操作符小于号会报错找不到函数定义

为何编译器会报找不到函数定义的错误呢?即使说两个<可能与左移位符冲突,但是改为<=也是一样报错说找不到函数定义,如果是>则不会报错,这其中是什么原因呢?

#include <iostream>
#include <string>

using namespace std;

template<typename T> class test;

template<typename T>
bool operator < (const test<T>& t1, const test<T>& t2) {
        return t1.t < t2.t;
}

template<typename T>
class test {
        friend bool operator < <T>(const test<T>& t1, const test<T>& t2);
public:
        test(const T& t):t(t){}
private:
        T t;
};

int main()
{
        test<intt1(1)t2(2);
        cout << (t1 < t2);
}

img

  • 写回答

1条回答 默认 最新

报告相同问题?

问题事件

  • 创建了问题 3月29日

悬赏问题

  • ¥15 如何改进这个简易的模数转换程序
  • ¥30 模拟电路 logisim
  • ¥15 PVE8.2.7无法成功使用a5000的vGPU,什么原因
  • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音
  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法