I have a function that I want to be able to accept const vector<const string>
but I also want the user to be able to pass vector<string>
as well. I thought I could just make the function argument be a reference to const and that a non-const vector would still be accepted, but it's not. Here's an example:
void test(const vector<const string> &v)
{
return;
}
int main( int argc, char *argv[] )
{
vector<string> v;
test(v);
return 0;
}
The error I receive is:
error C2664: 'test' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'const std::vector<_Ty> &'
Why doesn't the example work and how do you suggest I make my function work so the user can pass const vector<const string>
and vector<string>
? Thanks