I can initialize a 2D array of strings using the following:
const char * const aListOfStrings[] {"test","test1"};
However, if I want to do the same thing when calling a function, such as:
void function( char const * const aListOfStrings[] ) {}
void CallWithArrayOfStrings()
{
function( {"test", "test1"} );
}
The compiler politely refuses with the following error:
error: cannot convert '<brace-enclosed initializer list>' to 'char**'
I am able to pass a single string to a function as in:
void function( char const *someString ) {}
void CallWithString()
{
function( "test" );
}
I seem to understand how to initialize arrays when they are variables, but apparently I don't seem to understand how it works in the context of calling functions. I have always assumed that initializing a variable is the same as initializing a function parameter? Have I been living a lie my whole life? ;)
Thank you
UPATE: Removed C tag. C arrays require an '=' sign before the brace initializer, and the error is different. It appears the problem is very similar however...
Also fixed the closing quote.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…