0

Suppose I create a vector string v and pass this vector to parameter with vector string array, I got an compiler error: no matching function for call.

My Function

int functionA(vector <string> &a) //vector <string>  &a[] could not work
{}

Calling function in main:

vector <string> a;
for(int i =0 ; i < a.size(); i++)
{
 functionA(a[i]); //Error at this line...
}

functionA(a) should works but I want to use the array in the vector string. How can I do that ?

1
  • You would like to pass just a string or vector of strings? Commented Jan 31, 2014 at 3:45

2 Answers 2

3

If you would like to pass

A) vector of strings

Call:

vector <string> a;
..
..    
functionA(a); //notice this is not in for loop.

Function Signature:

int functionA(vector <string> &a)

B) only string.

call:

for (unsigned int i=0; i < (unsigned int)a.size();i++)
   functionA(a.at(i));

Function Signature:

int functionA(string &a)
{
Sign up to request clarification or add additional context in comments.

Comments

2
int functionA(vector <string> &a)

is a function that takes reference to vector<string> so you need to pass a vector to it:

vector <string> a;
...
functionA(a);

a[i] in your code is std::string, not a vector.


But if you want to pass a single string, then keep that loop and keep passing a[i], just change the function to:

int functionA(std::string& str)

Comments

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.