Valhalla Legends Forums Archive | C/C++ Programming | Struct as member of itself?

AuthorMessageTime
shadypalm88
I'm trying to get a pointer to a (typedef'd) struct inside itself.  I know that the addrinfo struct does it (albeit not typedef'd), but I'm having trouble doing the same.
[quote][color=aqua]typedef[/color] [color=aqua]struct[/color] _ofdpfolder {
    ucstr_t* name;
    [color=aqua]unsigned[/color] [color=aqua]long[/color] numFiles;
    [color=aqua]unsigned[/color] [color=aqua]long[/color] numFolders;
    ofdpfile_t* files;
    ofdpfolder_t* folders; [color=silver]// line 21[/color]
} ofdpfolder_t;[/quote]This is the code I'm trying to use, but gcc is telling me:
[quote="GNU C Compiler"]files.h:21: error: parse error before "ofdpfolder_t"[/quote]Any ideas on how I can get this to work properly?
December 20, 2004, 3:47 AM
Arta
change that line to:

[code]
struct ofdpfolder_t* folders; // line 21
[/code]
December 20, 2004, 4:47 AM
shadypalm88
Well, that didn't work, but I think I know what you meant.  Although I thought I had the line as [quote]struct _ofdpfolder* folders; [color=silver]// line 21[/color][/quote]before, and it didn't work, that's how it reads now, and it works fine.  Thanks.
December 20, 2004, 5:45 AM
Arta
hmm, yes, that'd be it. I never typedef my structs so I didn't notice :)
December 20, 2004, 7:03 AM

Search