Declaring an array of 10 elements in main would be as:
sample * plants = new sample [10];
My questions are:
Does there need to be a number of elements as shown in the square brackets, i.e. can it be left empty?
How would values be assigned to members of the structures in the array, especially the char arrays and how can it be done using curly brackets, filling all three member of each structure ?
Does there need to be a number of elements as shown in the square brackets, i.e. can it be left empty?
It cannot be left empty.
How would values be assigned to members of the structures in the array, especially the char arrays and how can it be done using curly brackets, filling all three member of each structure ?
skaa, is the void assignAll in the struct a type of constructor ?
stryku thanks for pointing out that the struct variable should be before the {} for each array element, I compile with tdm-gcc.
Is this only necessary for dynamic arrays and not for static ones ?
I think it relies on a fairly recent defect report resolution against C++14 (CWG 1467) which corrects aggregate-initialization to correctly initialize array members from string literals, hopefully gcc will catch up (I submitted https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67259 )