Tips48
Tips48

Reputation: 745

Method requires more than one argument?

So, I can't compile my code like this:

std::vector<std::string> split = split("A String Blah");  

with this method signature:

std::vector<std::string> split(const std::string& s)  

because it says it requires more than one argument. Why isn't just a string enough?

Upvotes: 0

Views: 100

Answers (1)

templatetypedef
templatetypedef

Reputation: 372852

When you have this line:

std::vector<std::string> split = split("A String Blah"); 

The C++ compiler thinks that the split referred to in the right-hand side is the same split declared on the left-hand side. As a result, it's giving you an error because, indeed, a std::vector<std::string> is not a function taking one argument.

To fix this, consider renaming the variable:

std::vector<std::string> theSplit = split("A String Blah"); 

Hope this helps!

Upvotes: 6

Related Questions