Erik Wikström
9/26/2008 3:36:00 PM
On 2008-09-26 15:49, bashill.zhu@gmail.com wrote:
> On 9æ??26æ?¥, ä¸?å?7æ?¶03å??, Pete Becker <p...@versatilecoding.com> wrote:
>> On 2008-09-26 04:51:56 -0400, "bashill....@gmail.com"
>> <bashill....@gmail.com> said:
>>
>>
>>
>>
>>
>> > bzhu@TY-PC /h/working/tcplex/ch8/testenum
>> > $ cat lexer.h
>> > namespace Lexer
>> > {
>> > enum Token_value;
>> > extern Token_value string_value;
>> > void get_token();
>> > }
>>
>> > bzhu@TY-PC /h/working/tcplex/ch8/testenum
>> > $ cat lexer.cpp
>> > #include "lexer.h"
>> > namespace Lexer{
>> > enum Token_value{
>> > one,two
>> > };
>> > }
>> > void Lexer::get_token()
>> > {
>> > }
>>
>> > bzhu@TY-PC /h/working/tcplex/ch8/testenum
>> > $ g++ -c lexer.cpp
>> > In file included from lexer.cpp:1:
>> > lexer.h:3: error: use of enum `Token_value' without previous
>> > declaration
>> > lexer.h:4: error: `Token_value' does not name a type
>>
>> You'd have the same problem if you used a forward declaration of a
>> class in place of an enum. In general, you can't create objects of
>> incomplete types, and "enum Token_value;" declares an incomplete type.
>> The code should have the complete definition of Token_value before it's
>> used.
Please do not quote signatures.
>
> I am wonder this reason , I just want declare a varible ,it's not
> definition.
Because the compiler does not know the size of a variable of type
Token_value until it has seen its definition. This means that you can
only declare pointers to Token_value (since the size of a pointer ti
known), but not variables.
--
Erik Wikström