typedef Syntax Error

M

Mike Copeland

I'm getting a syntax error on the "typedef" code line here. Any
thoughts on why? TIA


struct CSTYPE
{ // City/State Record
string csKey; // City/State "Key"
string csCity; // City
string csState; // State Code
};
typedef map<string, CSTYPE> CSINFO; // <=== error here
extern CSINFO cityStInfo;
extern map<string, CSTYPE>::iterator csIter;
extern CSTYPE workCS;
 
R

red floyd

   I'm getting a syntax error on the "typedef" code line here.  Any
thoughts on why?  TIA

struct CSTYPE
{                                              // City/State Record
        string csKey;                            // City/State "Key"
        string csCity;                                       // City
        string csState;                                // State Code};

typedef map<string, CSTYPE> CSINFO;  // <=== error here
        extern CSINFO cityStInfo;
        extern map<string, CSTYPE>::iterator csIter;
        extern CSTYPE workCS;


1. did you #include <map> and <string>?
2. map and string live in the std:: namespace
3. Would you care to describe the specific error?
 
M

Mike Copeland

I'm getting a syntax error on the "typedef" code line here. Any
It's possible that his compiler does not allow the use of incomplete
types as template arguments, even in typedefs, and 'CSTYPE' is
incomplete at that point...

Yes, but please see my common above. I _thought_ I had a complete
declaration for CSTYPE - am I wrong?
 
M

Mike Copeland

I'm getting a syntax error on the "typedef" code line here. Any
1. did you #include <map> and <string>?
2. map and string live in the std:: namespace
3. Would you care to describe the specific error?

I didn't state the error (C2143) because it's compiler-specififc
(VC++ 6.0) and I know that's a no-no here. 8<{{
I also didn't state that this is in a common .h file I'm building
(and I apologize for not mentioning that...)
 
J

James Kanze

It's possible that his compiler does not allow the use of
incomplete types as template arguments, even in typedefs, and
'CSTYPE' is incomplete at that point...

That wasn't the case in his original code. If you'll look at
the end of the line "string csState;", you'll see the closing
brace of CSTYPE. For some reasons, something in the news very
often seems to move a line with just a }: to the end of the
preceding line. (I've always suspected Google, because that's
what I use to read news, and I'm constantly seeing this.)

Without the closing brace, of course, the code would be illegal.
Because of the incomplete type, but also because you're not
allowed to use extern in a class either (and that error requires
a dignostic).

Like Mike, I rather suspect that he's either forgotten the
include, and he's clearly fogotten the std::. Which means that
string and map are unknown symbols. To reasonably parse C++,
the compiler needs to know when a symbol names a type; use an
unknown symbol where a type is required, the compiler will
generally suppose it isn't a type (which results in a syntax
error), and the quality of the error messages go downhill from
there.
 
J

James Kanze

Yes, but please see my common above.  I _thought_ I had a
complete declaration for CSTYPE - am I wrong?

You did. Your original posting was correct in this regard, but
something in the net seems to occasionally (often, in fact) join
a line with just a "}" or a "};" with the preceding line. If
the preceding line doesn't end with a comment, it doesn't affect
the legality of the code, but it is an unusual formatting. (I
asked about this once, since I was seeing so many postings with
this unusual formatting, and thought it might be some new coding
convention I wasn't familiar with. The poster in question
assured me that the }; was on a separate line when the posting
left his machine.)
 
R

red floyd

James said:
Like Mike, I rather suspect that he's either forgotten the
include, and he's clearly fogotten the std::.

Just FYI, that was me, not Mike.
 
R

Richard Herring

Mike Copeland said:
I didn't state the error (C2143) because it's compiler-specififc
(VC++ 6.0) and I know that's a no-no here. 8<{{

But you could tell us the *text* of the message, which might shed some
light. ;-)

Another possibility that nobody has mentioned is that you're including
some other header file which defines CSINFO or CSTYPE as a macro -
because of this, it's often a good idea to avoid using all-caps
identifiers for anything else.
 
M

Mike Copeland

I didn't state the error (C2143) because it's compiler-specififc
There is no reason I know of to use VC++ 6.0 when you can download VC++ 8.0
for free from Microsoft which is much better and up to date. See here.
http://www.microsoft.com/express/download/

Any way I try to get to this site, I get an error (Unable to load XML
manifest...(etc.). Is this normal, or temporary? TIA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top