gcc报invalid operands of types ‘<unresolved overloaded function type>‘ and ‘int‘ to binary ‘operator<_<unresolved overloaded function type>’ and ‘float’-CSDN博客c++ - CPP templated member function specialization - Stack Overflow
1 背景
在用template写一个DataFrame的索引DEMO时,编译器报:
invalid operands of types ‘<unresolved overloaded function type>‘ and ‘int‘ to binary ‘operator<对应的代码结构类似:
template<typename T>
class Statement;
template<typename T>
class DataFrame{
public:
template<IndexType IT, typename...Args>
IndexValVecType getIdxs(const Arg&...args)const{
.....
}
};
template<typename T>
class Statement{
public:
template<IndexType IT, typename KeyType>
Statement& cond(const KeyType&key){
oper(m_df.getIdxs<IT>(key)); // 这里编译出错
return *this;
}
};2 原因
主要原因是gcc编译器不清楚getIdxs是成员函数还是成员变量,在这里把它识别成了成员变量,将<作为小于号使用。
3 解决方案
在调用时增加关键词template,指明调用的是模板函数:
oper(m_df.template getIdxs<IT>(key));即可编译通过。问题解决!