使用字符串类型的取消引用矢量迭代器作为函数参数
Using dereferenced Vector iterator of type string as function argument
我正在用迭代一个向量
std::vector<std::string>::reverse_iterator ritr;
我需要在某个时刻找出这个向量中的字符串是否是使用函数的运算符
bool IsOperator(const std::string s);
当我按照以下方式调用函数时,
if(IsOperator(*ritr))
eclipse抱怨!
Candidates are:
bool IsOperator(char)
bool IsOperator(std::basic_string<char,std::char_traits<char>,std::allocator<char>>)
(我有一个重载函数,它接受char
而不是std::string
)然而,它允许将延迟迭代器存储在字符串中的操作
std::string str= *ritr;
我在这里错过了什么?
您的代码很好。消除isOperator(char)
和isOperator(string)
之间的歧义不是问题,因为string
不能隐式转换为char
。
我希望你的程序能够编译(如果没有,那就说明你没有显示其他东西),而IDE抱怨红色的歪歪扭扭只意味着你的IDE有一个bug。
此外,还有几点意见:
我有一个
std::vector<std::string>
类型的函数
函数不能具有类型std::vector<std::string>
。它可以返回类型为std::vector<std::string>
的值,也可以接受一个值。我猜你是指后者。
bool IsOperator(const std::string s)
这个函数签名没有多大意义。您的意思可能是接受对std::string
对象的常量引用:
bool IsOperator(std::string const& s)
相关文章:
- 如何在C++中将迭代器作为函数参数传递
- 定义模板参数的迭代器类型
- 当通知迭代器参数初始化为空列表的开头时,list::insert 行为是什么?
- 具有C++迭代器参数的多功能函数
- C++如何获取传递给函数(STL 迭代器)的参数的名称
- 当迭代器(输入参数)通常不是constexpr时,constexpr算法真的有用吗
- 迭代器的模板参数:函数在调用时推断类型?
- 接受迭代器作为参数并存储值的类?
- 我的代码在作为参数传入 .begin() 时不起作用,但在我将 .begin() 转换为迭代器后工作
- 如何使用迭代器作为参数方法?
- 调用模板函数的问题"No matching function for call"参数:迭代器、对象函数
- 使用 std::vector<Particle> 粒子;函数 .at() 不能与迭代器一起使用,它作为 for 循环中的参数
- 如何确保函数模板的参数是随机访问迭代器
- 使用迭代器和可变参数模板的笛卡尔乘积
- 从具有迭代器参数的模板函数返回指针
- 英特尔检查器 XE 2012 警告 #12367 - 将迭代器参数切片传递给 vector::erase()
- 容器不可知迭代器参数
- 将可变迭代器参数转换为值类型的元组
- 模板方法中的迭代器参数出现问题
- 为什么标准库函数中没有提供带有迭代器参数的重载?