I need a way to cast between these two types of variables:
std::array< const char*, 3 >* foo;
const char* foo[][3];
Because I need to be able to pass both types to a function. The function can be defined either of these ways, whichever makes conversion easier:
void bar( std::array< const char*, 3 >* param );
void bar( const char* param[][3] );
In this question, Jarod42 suggests using the method here. Is there a cleaner way to do this?
Edit in response to dyp's link
This reinterpret_cast
did work for me, but Ivan Shcherbakov describes it as an "ugly dirty hack" I've pasted the code, below... I don't understand why this is a hack, or why something could go wrong with it? Is the template method suggested by Nathan Monteleone necessarily better than this?
void bar( std::array< const char*, 3 >* param ){}
void main( void )
{
static const char* cStyle[][3] = { NULL };
std::array< const char*, 3 > foo = { NULL };
std::array< const char*, 3 >* stlStyle = &foo;
bar( reinterpret_cast< std::array< const char*, 3 >* >( cStyle ) );
bar( stlStyle );
}