Hi everyone,
I'm trying to create a dynamic array to display information in a structure....now keep in mind I'm fairly new to C++. Here's what I have:
struct CandyBar
{
char brand[20];
float weight;
int calories;
};
int main()
{
CandyBar* p_candy = new CandyBar[3];
p_candy[0] = {"Chunky", 3.5, 200};
p_candy[1] = {"Monkey", 3.4, 100};
p_candy[2] = {"Choco", 3.3., 50};
------------------------------------------------------------
Now, this doesn't work obviously, and I'm curious how i can create a dynamic array to access structure members. I'm under the impression that to create a dynamic array, you need the type, and the pointer set to a memory location of the type...so whatever I'm doing wrong I just don't understand.. Any help would be great. thanks -Chap PS tell me if you need any more info



LinkBack URL
About LinkBacks



