0

I am iterating through a vector with

std::vector<std::string>::reverse_iterator ritr; 

I need to at some point find out if a string in this vector is an operator using the function

bool IsOperator(const std::string s);

When I call the function following way,

if(IsOperator(*ritr))

eclipse complains!

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

(I have an overloaded function with accepts char instead of std::string) However, it allows the operation of storing the deferenced iterator in a string

std::string str= *ritr;

What am I missing here?

7
  • 6
    How does it complain? Commented Feb 20, 2013 at 15:31
  • Also, you might consider using references instead of string copies. Commented Feb 20, 2013 at 15:32
  • Please show the real code Commented Feb 20, 2013 at 15:37
  • 4
    You need to post some more code showing the function declaration, how you're creating the iterator etc. If the iterator truly is std::vector<string>::iterator, the compiler should have no trouble disambiguating between those two functions. Also, are you saying compilation fails, or is it Eclipse CDT's parser that's showing red squiggles? Commented Feb 20, 2013 at 15:37
  • I have specified the function declaration. Yes, it is the Eclipse CDT parser with red squiggles (learnt a new word) Commented Feb 20, 2013 at 15:41

1 Answer 1

2

Your code is fine. Disambiguating between isOperator(char) and isOperator(string) is not a problem, because a string cannot be implicitly converted to a char.

I expect your program to compile (if it doesn't, there's something else you are not showing), while the IDE complaining with red squiggles just means that your IDE has a bug.


Also, a few remarks:

I have a function of type std::vector<std::string>

A function cannot not have type std::vector<std::string>. It can return a value of type std::vector<std::string>, or it can accept one. I guess you meant the latter.

bool IsOperator(const std::string s)

This function signature doesn't make much sense. You probably meant accepting a constant reference to an std::string object:

bool IsOperator(std::string const& s)
Sign up to request clarification or add additional context in comments.

4 Comments

I meant vector type. Sorry. And yes it needs to be const reference. It is a problem with eclipse. Any way to fix it?
@user592748: I do not use Eclipse, so I don't know unfortunately.
What do you use, if I may ask?
@user592748: Mostly notepad :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.