繁体   English   中英

使用类型为string的dereferenced Vector迭代器作为函数参数

[英]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))

日食抱怨!

Candidates are: bool IsOperator(char) bool IsOperator(std::basic_string<char,std::char_traits<char>,std::allocator<char>>)

(我有一个重载函数,接受char而不是std::string )但是,它允许将deferenced迭代器存储在字符串中的操作

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM