473,378 Members | 1,104 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,378 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 11122
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.