TITLE: What is the relationship between typedef and struct/class? PROBLEM: davis@ilog.fr (Harley Davis) The following code compiles fine on Sun C++ 3.0.1 (Sun OS 4.1) and on HP C++ 3.4 but produces an error message on Sun C++ 4.0 (Solaris 2.3). The error message is reproduced below. Who's right? [ "classstruct.cc", line 3: Error: Multiple declaration for foo. ] typedef struct { int a; } foo; class foo* bar () { return new foo;} struct foo* goo () { return new foo;} foo* gee () { return new foo; } RESPONSE: clamage@Eng.Sun.COM (Steve Clamage), 17 Nov 94 The ARM left unanswered whether typedef struct { ... } foo; and struct foo { ... }; were equivalent. This is not a trivial question, because suppose we have typedef struct { ... } foo; typedef foo bar; Clearly 'foo' and 'bar' are the same type. But should I be able to say both 'struct foo' and 'struct bar' interchangeably? Normally I could not; a struct cannot have two different tags. Worse, what is the name of the default constructor for the struct? foo::foo()? bar::bar()? You can't write both functions, because you would then have two functions that are supposed to be just one function. And how could the compiler or human reader figure out what constructor was called when you said bar b; That is, did you supply foo::foo() or bar::bar()? The C++ Committee resolved these issues by saying that a typedef name cannot be used as a class name. Further the class denoted by your original typedef has no user-accessible name. Such a class cannot have a constructor or destructor, since it has no name which can be used. The C++ Committee Working Paper contains an example very much like yours to illustrate invalid use of typedefs. Section 7.1.3, The typedef specifier.