I'm new to C++ (math major here). Here's a simple example of what I'm trying to do.
Suppose I have some struct, we'll call it simple.
Code:
typedef struct simple
{
int a;
}simple;
Now, suppose I have another struct that contains some data, and an std::list that will hold type simple:
Code:
typedef struct _tx_info
{
int something;
list<simple*> simple_list;
}tx_info;
Now, in main, if I want to create a type of tx_info, and use that list, I'm not sure what the
syntax is just to instantiate the list..
Code:
int main(int argc, char ** argv)
{
tx_info * info = (tx_info*)malloc(sizeof(tx_info));
simple * s = (simple*)malloc(sizeof(simple));
s->a = 10;
info->simple_list.push_front(s);
return 0;
}
Obviously, this will segfault because I never instantiate the list.
What's confusing to me, is if at the top of the C++ file, I do
Code:
list<simple*> simple_list;
that will both declare and instantiate a list. I'm not sure how to instantiate it when my list is
declared within a struct.
Thanks so much for the help!