Possible Duplicate:
Forward declarations of unnamed struct
If I have
typedef struct tagPAGERANGE
{
int iFirstPage;
int iLastPage;
} PAGERANGE;
I can forward declare it that way
struct tagPAGERANGE;
typedef struct tagPAGERANGE PAGERANGE;
But what I have is
typedef struct
{
int iFirstPage;
int iLastPage;
} PAGERANGE;
I'm not sure how I can do it. I only want to hold a pointer to this struct. Right now I'm stuck with either including a rather substantial header, or duplicating the definition of the struct.
It's impossible. You can only declare named structs.
Think about what identifies a struct that doesn't have a name, and how do you tell the compiler that it's that struct you want. If it doesn't have a name, it's identified by its members, so you need to provide members — i.e. define it. Therefore, you can't just declare it — you don't have a luxury of an identifier other than the definition itself.
Since this is used in a C++ code, just get rid of the typedefs altogether, they are unnecessary and bad style in C++.
The real solution is to just use named structs:
struct foo; // forward declaration
struct foo {
// … implementation
};
The typedefs are not useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With