GNU g++ 4.9.2 查找函数调用的编译错误
GNU g++ 4.9.2 Compilation Error for a find function call
我将StringVec定义为:
typedef std::vector<string> StringVec;
变量并列定义为:
StringVec colnames;
我有一个功能如下:
int colIndex(const string &cn) const {
StringVec::iterator i1;
i1 = find(colnames.begin(),colnames.end(),cn);
return(i1 == colnames.end() ? -1 : (i1 - colnames.begin()));
}
当我尝试使用 GNU g++ 4.9.2 (C++11) 编译时,它抱怨:
error: no matching function for call to 'find(std::vector<std::basic_string<char> >::const_iterator, std::vector<std::basic_string<char> >::const_iterator, const string&)'
i1 = find(colnames.begin(),colnames.end(),cn);
即使是std::find
也无法解决这个问题。编译器给出了另一个线索:
note: template argument deduction/substitution failed:
note: '__gnu_cxx::__normal_iterator<const std::basic_string<char>*, std::vector<std::basic_string<char> > >' is not derived from 'std::istreambuf_iterator<_CharT>'
i1 = std::find(colnames.begin(),colnames.end(),cn);
有什么线索吗?
根据您提供的信息,我做了一个最小的例子(经过最少的修改,您是否包括了标题?
#include <string>
#include <algorithm>
#include <vector>
typedef std::vector<std::string> StringVec;
StringVec colnames;
int colIndex(const std::string &cn) {
StringVec::iterator i1;
i1 = std::find(colnames.begin(),colnames.end(),cn);
return(i1 == colnames.end() ? -1 : (i1 - colnames.begin()));
}
int main() {
return 0;
}
它与 G++ 4.8.4 编译得很好:
gsamaras@gsamaras-A15:~$ g++ -Wall px.cpp
gsamaras@gsamaras-A15:~$
相关文章:
- C++:编译时检查匹配的函数调用对?
- C++11:模板方法的模板函数调用无法编译?
- 内联扩展编译为函数调用 [C++]
- C++根据调用的构造函数强制编译时错误
- 为什么缺少名称的函数调用仍然可以编译
- C++:编译对无关派生类、bug或特性的函数调用
- 函数调用中出现意外编译错误 (C++)
- 调用 Parse int 函数时编译 parse 整数程序时出现问题
- C++ - 在 std::thread 中调用重载函数时编译失败
- 在其他构造函数的调用中调用构造函数时C++编译错误
- C函数调用C 成员函数 - 其中C代码与C编译器编译
- 对 constexpr 与内联函数的调用编译为不同的程序集,并禁用优化
- 编译时动态函数调用
- 重载函数调用编译时常量
- 使用函数调用初始化静态全局数据(在编译时)
- 如何告诉编译器向编译的每个函数添加一个函数调用
- GNU g++ 4.9.2 查找函数调用的编译错误
- 调用一个空基类函数,编译时会发生什么
- C++中的编译时条件成员函数调用
- 为什么VS2013将函数调用编译成两个指令而不是一个