Topic: Forward declaration of anonymous struct
Author: Martin von Loewis <loewis@informatik.hu-berlin.de>
Date: 1999/03/22 Raw View
jgro@netcom.com (Jeremy) writes:
> How can I forward declare an anonymous struct?
You can't.
> In this example, how do I make a typedef name for the
> CORBA_sequence_FooT that will be acceptable both before and after
> seeing the definition?
You can make the typedef name the same as the class name, as in
struct Bla;
typedef struct Bla{
int xyz;
}Bla;
Bla bla;
> Is there any reference material that you would suggest to help me in
> answering questions like that in the future? I've already tried
> Stroustrup and the ISO standard without luck.
These are the references. If you study them carefully, you'll find
that you simply can't do what you want to do, at least not in standard
C++. Sometimes, they are explicit about how things work and how they
don't. At other times (like this case), they only help to confirm that
the compiler is right.
For 'questions like that', there is always a chance that they are
answered in the C++ FAQ.
Regards,
Martin
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: jgro@netcom.com (Jeremy)
Date: 1999/03/19 Raw View
How do you forward declare an anonymous struct?
I have some CORBA generated headers that include stuff like this:
extern "C" {
typedef struct FooT { /* stuff */ } FooT;
typedef struct {
CORBA_unsigned_long _maximum;
CORBA_unsigned_long _length;
FooT * _buffer;
} CORBA_sequence_FooT;
typedef CORBA_sequence_FooT FooSeq;
} // end extern C
Well, the header is huge and I don't want to include it everwhere.
My old compiler (g++ 2.7) let me get away with using this as a forward
declaration as well as a typedef:
typedef struct FooT MyFoo;
struct CORBA_sequence_FooT;
typedef CORBA_sequence_FooT MyFooSeq;
Then I could use MyFoo and MyFooSeq everywhere and only include the
CORBA header when I needed a fully-defined type.
Under the Standard C++ compiler, this doesn't work, because if it sees
the CORBA header before my forward declarations, it complains that
"struct CORBA_sequence_FooT;" is using a typdef name in an elaborated
type specifier (which it is).
************** Here is my question **************
How can I forward declare an anonymous struct?
In this example, how do I make a typedef name for the
CORBA_sequence_FooT that will be acceptable both before and after
seeing the definition?
************* End question ************
Is there any reference material that you would suggest to help me in
answering questions like that in the future? I've already tried
Stroustrup and the ISO standard without luck.
Thanks.
--
Jeremy Grodberg
jgro@netcom.com
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]