473,770 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_toke n()
{
}

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 11154
ba*********@gma il.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*********@gm ail.com"
<ba*********@gm ail.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_toke n()
{
}

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.d ewrote:
bashill....@gma il.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_val ue" 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@H ILL /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@H ILL /m/working/tcplex/ch8/testenum
$ cat lexer.cpp
#include "lexer.h"
namespace Lexer{
Token_value string_value;
}
Token_value Lexer::get_toke n()
{
return one;
}

Administrator@H ILL /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...@versatile coding.comwrote :
On 2008-09-26 04:51:56 -0400, "bashill....@gm ail.com"
<bashill....@gm ail.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_toke n()
{
}
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*********@gma il.com wrote:
On 9鏈26鏃, 涓嬪崍7鏃03鍒 , Pete Becker <p...@versatile coding.comwrote :
>On 2008-09-26 04:51:56 -0400, "bashill....@gm ail.com"
<bashill....@g mail.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_toke n()
{
}
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*********@gm ail.com"
<ba*********@gm ail.comsaid:
>
Administrator@H ILL /m/working/tcplex/ch8/testenum
$ cat lexer.cpp
#include "lexer.h"
namespace Lexer{
Token_value string_value;
}
Token_value Lexer::get_toke n()
{
return one;
}

Administrator@H ILL /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_va lue.

--
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...@versatile coding.comwrote :
On 2008-09-26 09:41:53 -0400, "bashill....@gm ail.com"
<bashill....@gm ail.comsaid:


Administrator@H ILL /m/working/tcplex/ch8/testenum
$ cat lexer.cpp
#include "lexer.h"
namespace Lexer{
Token_value string_value;
}
Token_value Lexer::get_toke n()
{
return one;
}
Administrator@H ILL /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_va lue.

--
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_va lue Lexer::get_toke n()
{
return one;
}

Sep 27 '08 #8

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

Similar topics

20
4850
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 EnumName FirstValue = 1 SecondValue = 2 ThirdValue = 3
5
5103
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
4603
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
3616
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(); Control c = f; An enum value inherits from int but it doesn't get implicitly converted: HorizontalAlignment h = HorizontalAlignment.Center;
13
12392
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
23611
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 FOO_STORE to be, say -10, I get a warning about unsigned comparison and I'm seeing an infinite loop. If I do initialize FOO_STORE = -10, I don't see any warnings. No infinite loop.
34
11204
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 snippet that I wrote today that gives me an instant implementation of the pattern. I could easily just always use such an implementation instead of a standard enum, so I wanted to know what you experts all thought. Is there a case for standard enums?
1
2133
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 declaration is as below. The problem is in "struct _WLAN_AVAILABLE_NETWORK_LIST", it declared "WLAN_AVAILABLE_NETWORK Network;". I think which means a Network array of struct WLAN_AVAILABLE_NETWORK.
0
311
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
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we抣l explore What is ONU, What Is Router, ONU & Router抯 main usage, and What is the difference between ONU and Router. Let抯 take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10260
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project梡lanning, coding, testing, and deployment梬ithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.