[newbie] list with structures

G

Guest

Hi

I try to use the C++ std class "list" to create my linked list in my MFC app. Now, this list shall contain instances of a structure, like

typedef struct _MYSTRUCT
int a
int b
}MYSTRUCT

How can I create a linked list of that

Thanks a lo
Peter
 
D

David Lowndes

I try to use the C++ std class "list" to create my linked list in my MFC app. Now, this list shall contain instances of a structure, like:
typedef struct _MYSTRUCT {
int a;
int b;
}MYSTRUCT;

How can I create a linked list of that?

#include <list>

std::list<MYSTRUCT> mylist;

Dave
 
C

Carl Daniel [VC++ MVP]

Peter said:
Hi,

I try to use the C++ std class "list" to create my linked list in my
MFC app. Now, this list shall contain instances of a structure, like:

typedef struct _MYSTRUCT {
int a;
int b;
}MYSTRUCT;

How can I create a linked list of that?

See David's reply. While you're at it, get rid of the C-style struct
declaration. Just use

struct MYSTRUCT
{
int a;
int b;
};

The typedef hack is necessary in C because a struct declaration in C doesn't
define a type. In C++ it does.

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top