900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > gcc报invalid operands of types ‘<unresolved overloaded function type>‘ and ‘int‘ to binary ‘operator<

gcc报invalid operands of types ‘<unresolved overloaded function type>‘ and ‘int‘ to binary ‘operator<

时间:2023-01-06 22:45:45

相关推荐

gcc报invalid operands of types ‘<unresolved overloaded function type>‘ and ‘int‘ to binary ‘operator<

会报这个错,基本上就是这么个情况。

object->function<var>(par,par);这么用的时候gcc把<var>这个尖括号的左边识别成了小于号。

解决也很简单。最后还是在s站找到的答案。c++ - CPP templated member function specialization - Stack Overflow

按照我的理解,简单来说就是,编译器读到function < var这里的时候,它不知道这个function是个函数还是个变量,或者说它误认为这个function是变量,所以<就理解为小于号,而不是尖括号的一部分。

解决方法就是在function左侧加上template关键字,告诉编译器,这是个用了模版的函数。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。