Reputation: 7853
I have a Visual Studio 2008 C++ application where I'm using a function that accepts an array of pairs of null-terminated strings:
/// @brief count - number of pairs
/// @brief pairs - pairs of strings
void Foo( int count, const char* pairs[][ 2 ] );
I have a std::vector< char >
that contains character strings separated by null-terminators. I'd like to be able to do something like this:
std::vector< char > my_pairs;
Foo( pair_count, ( const char* pairs[][ 2 ] )&my_pairs.front() );
But, compiler reminds me that is not possible:
error C2440: 'type cast' : cannot convert from 'char *' to 'const char *[][2]'
Is there a way to make this work?
Thanks, PaulH
Upvotes: 0
Views: 549
Reputation: 145269
Function Foo
expects an array of pairs of pointers.
In your vector you have characters.
You need to create an array of pairs of pointers. The easiest is to initialize those pointers to point into your vector's buffer.
Upvotes: 1