I am trying to allocate a dynamic string array in the following way and I get an error:
struct Test
{
std::string producer[];
std::string golden[];
};
Test test1 =
{
{"producer1", "producer2"} ,
{"golden1" , "golden2"}
};
The error i get is that there are too many initializers for std::string[0],
but if I get off the array part it works:
struct Test
{
std::string producer;
std::string golden;
};
Test test1 =
{
"producer1" ,
"golden1"
};
Thanks in advance!
You cannot initialize zero-sized arrays this way, because you have to dynamically allocate the memory. You can only do what you do if you specify the dimensions in the type definition.
See my answer to a similar question here.