473,320 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to declare an enum type?

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

Thanks !

Sep 26 '08 #1
7 11118
ba*********@gmail.com wrote:
[...]
$ g++ -c lexer.cpp
In file included from lexer.cpp:1:
lexer.h:3: error: use of enum `Token_value' without previous
declaration
That should probably read "definition".
lexer.h:4: error: `Token_value' does not name a type

Thanks !
What's your point?

Schobi
Sep 26 '08 #2
On 2008-09-26 04:51:56 -0400, "ba*********@gmail.com"
<ba*********@gmail.comsaid:
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.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Sep 26 '08 #3
On 9月26日, 下午4时59分, Hendrik Schober <spamt...@gmx.dewrote:
bashill....@gmail.com wrote:
[...]
$ g++ -c lexer.cpp
In file included from lexer.cpp:1:
lexer.h:3: error: use of enum `Token_value' without previous
declaration

That should probably read "definition".
lexer.h:4: error: `Token_value' does not name a type
Thanks !

What's your point?

Schobi
I want write a modual that expose a "string_value" var which type is
enum Token_value.
and a function "get_token" which
returns a Token_value var.
I modify the code,but it still has errors:
Administrator@HILL /m/working/tcplex/ch8/testenum
$ cat lexer.h
namespace Lexer
{
enum Token_value{
one,two
};
extern Token_value string_value;
Token_value get_token();
}

Administrator@HILL /m/working/tcplex/ch8/testenum
$ cat lexer.cpp
#include "lexer.h"
namespace Lexer{
Token_value string_value;
}
Token_value Lexer::get_token()
{
return one;
}

Administrator@HILL /m/working/tcplex/ch8/testenum
$ g++ -c lexer.cpp
lexer.cpp:5: error: `Token_value' does not name a type
Sep 26 '08 #4
On 9月26日, 下午7时03分, Pete Becker <p...@versatilecoding.comwrote:
On 2008-09-26 04:51:56 -0400, "bashill....@gmail.com"
<bashill....@gmail.comsaid:


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.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)- 隐藏被引用文字 -

- 显示引用的文字 -
I am wonder this reason , I just want declare a varible ,it's not
definition.
Sep 26 '08 #5
On 2008-09-26 15:49, ba*********@gmail.com wrote:
On 9鏈26鏃, 涓嬪崍7鏃03鍒, Pete Becker <p...@versatilecoding.comwrote:
>On 2008-09-26 04:51:56 -0400, "bashill....@gmail.com"
<bashill....@gmail.comsaid:


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
Sep 26 '08 #6
On 2008-09-26 09:41:53 -0400, "ba*********@gmail.com"
<ba*********@gmail.comsaid:
>
Administrator@HILL /m/working/tcplex/ch8/testenum
$ cat lexer.cpp
#include "lexer.h"
namespace Lexer{
Token_value string_value;
}
Token_value Lexer::get_token()
{
return one;
}

Administrator@HILL /m/working/tcplex/ch8/testenum
$ g++ -c lexer.cpp
lexer.cpp:5: error: `Token_value' does not name a type
The second mention of Token_value, as the compiler says, does not name
a type. Nor does it name anything else. Its proper name is
Lexer::Token_value.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Sep 26 '08 #7
On 9月27日, 上午2时19分, Pete Becker <p...@versatilecoding.comwrote:
On 2008-09-26 09:41:53 -0400, "bashill....@gmail.com"
<bashill....@gmail.comsaid:


Administrator@HILL /m/working/tcplex/ch8/testenum
$ cat lexer.cpp
#include "lexer.h"
namespace Lexer{
Token_value string_value;
}
Token_value Lexer::get_token()
{
return one;
}
Administrator@HILL /m/working/tcplex/ch8/testenum
$ g++ -c lexer.cpp
lexer.cpp:5: error: `Token_value' does not name a type

The second mention of Token_value, as the compiler says, does not name
a type. Nor does it name anything else. Its proper name is
Lexer::Token_value.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)- 隐藏被引用文字 -

- 显示引用的文字 -
Thanks Pete and Eric:
I have got what I want .

$ cat lexer.h
namespace Lexer
{
enum Token_value{
one,two
};
extern Token_value string_value;
Token_value get_token();
}

bzhu@TY-PC /h/working/tcplex/ch8/testenum
$ cat lexer.cpp
#include "lexer.h"
namespace Lexer
{
Token_value string_value;
}
Lexer::Token_value Lexer::get_token()
{
return one;
}

Sep 27 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Glenn Venzke | last post by:
I'm writing a class with a method that will accept 1 of 3 items listed in an enum. Is it possible to pass the item name without the enum name in your calling statement? EXAMPLE: public enum...
5
by: Woon Kiat | last post by:
Hi, Using IDL, I can declare my enumeration like following, library MyAppLib { importlib("stdole32.tlb"); importlib("stdole2.tlb"); typedef enum MyColor
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
31
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1();...
13
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType = ???(enumName)
10
by: kar1107 | last post by:
Hi all, Can the compiler chose the type of an enum to be signed or unsigned int? I thought it must be int; looks like it changes based on the assigned values. Below if I don't initialize...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
1
by: peary | last post by:
Hi, everyone, I'm writing a program to discover wireless network using Windows Native Wifi API & VB.net. I have to declare the windows API in my VB.net program. The original windows...
0
by: bashill.zhu | last post by:
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
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you抣l learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.