I am not really used to coding in C++ and this probably is a simple issue that I am not able to get the correct syntax of.
What I am basically trying to achieve is that, from one method where I declare an array of a struct (size not specified), I call a method where I pass this array. The method should initialize the values of the array. I tried to get a simple code working but getting errors. The following piece of code gives me a compilation error. Can someone point out how to achieve this?
struct ABC
{
int a;
int b;
};
void test(ABC * a)
{
a[] = {{2,3},{4,5}};
}
int main() {
ABC arr[2];
test(arr);
}
EDIT:
The following works, but I would like the initialization to work in one line.
struct ABC
{
int a;
int b;
};
void test(ABC *a)
{
a[0].a = 2;
a[0].b = 3;
a[1].a = 4;
a[1].b = 5;
}
int main() {
ABC arr[2];
test(arr);
}