Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > typedef Syntax Error

Reply
Thread Tools

typedef Syntax Error

 
 
Mike Copeland
Guest
Posts: n/a
 
      10-31-2008
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;

 
Reply With Quote
 
 
 
 
red floyd
Guest
Posts: n/a
 
      10-31-2008
On Oct 31, 2:01*pm, (E-Mail Removed) (Mike Copeland) wrote:
> * *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?
 
Reply With Quote
 
 
 
 
Mike Copeland
Guest
Posts: n/a
 
      10-31-2008
> >> 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
> >> }; <==== this was in my post, but was appended to the above line.
> >>
> >> 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?

>
> 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?
 
Reply With Quote
 
Mike Copeland
Guest
Posts: n/a
 
      10-31-2008
> > 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?


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...)
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      11-01-2008
On Oct 31, 10:16*pm, Victor Bazarov <(E-Mail Removed)>
wrote:
> red floyd wrote:
> > On Oct 31, 2:01 pm, (E-Mail Removed) (Mike Copeland) wrote:
> >> 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?


> 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.

--
James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      11-01-2008
On Oct 31, 10:43*pm, (E-Mail Removed) (Mike Copeland) wrote:
> > >> * *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
> > >> }; *<==== this was in my post, but was appended to the above line.


> > 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?


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.)

--
James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

 
Reply With Quote
 
Jim Langston
Guest
Posts: n/a
 
      11-01-2008

"Mike Copeland" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>> > 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?

>
> 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<{{


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/

> I also didn't state that this is in a common .h file I'm building
> (and I apologize for not mentioning that...)


 
Reply With Quote
 
Bo Persson
Guest
Posts: n/a
 
      11-01-2008
Jim Langston wrote:
> "Mike Copeland" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>>> 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?

>>
>> 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<{{

>
> 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/
>


That's VC9 even, telling us that VC6 is just ancient. Don't use it
unless someone is pulling your toenails out!


Bo Persson


 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      11-02-2008
James Kanze wrote:

> 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.
 
Reply With Quote
 
Richard Herring
Guest
Posts: n/a
 
      11-03-2008
In message <(E-Mail Removed)>, Mike Copeland
<(E-Mail Removed)> writes
>> > 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?

>
> 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.

> I also didn't state that this is in a common .h file I'm building
>(and I apologize for not mentioning that...)


--
Richard Herring
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CRTP-problem: How can the base class typedef a derived class' typedef? oor C++ 0 05-20-2008 12:39 PM
Syntax error? What syntax error? Assignment fo default values? Mark Richards Perl Misc 3 11-18-2007 05:01 PM
Syntax bug, in 1.8.5? return not (some expr) <-- syntax error vsreturn (not (some expr)) <-- fine Good Night Moon Ruby 9 07-25-2007 04:51 PM
a question about typedef syntax Jess C++ 5 06-11-2007 08:38 PM
Complier error!! error C2059: syntax error : '(' Balaji C++ 3 12-03-2004 11:19 PM



Advertisments