PDA

Click to See Complete Forum and Search --> : Forward Declaration


miben
Mar 15th, 2002, 04:02 PM
I have 2 structures that contain each other..

typedef struct tagUSER {
long lName
GROUP group
const char *lpszPass
}; USER

typdef struct tagGROUP {
long lID
USER user
}; GROUP

It doesnt work. Is there a way to forward the declaration for the
structures so they can see each other?

Zaei
Mar 15th, 2002, 10:02 PM
Placing the line:

struct tagGROUP;

before the first struct should solve the problem.

Z.

CornedBee
Mar 17th, 2002, 09:37 AM
It does not and it's good that way. Two structs that contain each other (or one that contains itself) would actually need infinite memory.

If you need something like this, keep a pointer to a struct of the other type, but don't create access violations :)

Then you still need a forward declaration like Zaei showed.


And the alternative names for your structs must come before the semicolon:
} GROUP;

Zaei
Mar 17th, 2002, 10:14 PM
Oh, I didnt catch that =(.

Z.