枚举 [英] Enumerations

查看:101
本文介绍了枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会试着解释一下我想做什么:


我有foo.h和foo.cpp。包含foo.h的单位将定义一个

枚举栏:


enum bar {typeNone,typeBaz,typeQuux,...,count};


foo.cpp中定义的方法需要返回typeNone。正在使用


static_cast< bar>(0)

可以接受吗?


此外,foo.cpp中的方法需要返回typeBaz,typeQuux等。

有没有办法指定这些是条形枚举的值

而没有实际定义条形(因为包含foo.h的单位将

取关心那个)?


-

Christopher Benson-Manica |我*应该*知道我在说什么 - 如果我

ataru(at)cyberspace.org |不,我需要知道。火焰欢迎。

I''ll try to explain what I want to do:

I have foo.h and foo.cpp. Units that include foo.h will define an
enumeration bar:

enum bar { typeNone, typeBaz, typeQuux, ... , count };

A method defined in foo.cpp needs to return typeNone. Is using

static_cast< bar >( 0 )

acceptable?

Also, methods in foo.cpp need to return typeBaz, typeQuux, etc. Is
there any way to specify that these are values of the bar enumeration
without actually defining bar (since units that include foo.h will
take care of that)?

--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.

推荐答案

在21/7/04 8:46 pm,在文章cd ********** @ chessie .cirr.com,克里斯托弗

Benson-Manica <在*** @ nospam.cyberspace.org>写道:
On 21/7/04 8:46 pm, in article cd**********@chessie.cirr.com, "Christopher
Benson-Manica" <at***@nospam.cyberspace.org> wrote:
我会试着解释一下我想做什么:

我有foo.h和foo.cpp。包含foo.h的单位将定义一个
枚举栏:

枚举栏{typeNone,typeBaz,typeQuux,...,count};

一种方法在foo.cpp中定义的需要返回typeNone。正在使用

static_cast<吧>(0)

可以接受吗?



我错过了一些明显的东西吗?为什么不返回typeNone?


另外,foo.cpp中的方法需要返回typeBaz,typeQuux等。是否有任何方法可以指定这些是bar枚举
没有实际定义bar(因为包含foo.h的单位会照顾它)?
I''ll try to explain what I want to do:

I have foo.h and foo.cpp. Units that include foo.h will define an
enumeration bar:

enum bar { typeNone, typeBaz, typeQuux, ... , count };

A method defined in foo.cpp needs to return typeNone. Is using

static_cast< bar >( 0 )

acceptable?

Am I missing something obvious? Why not just return typeNone?

Also, methods in foo.cpp need to return typeBaz, typeQuux, etc. Is
there any way to specify that these are values of the bar enumeration
without actually defining bar (since units that include foo.h will
take care of that)?



foo.cpp #including foo.h ?

史蒂夫。


Is foo.cpp #including foo.h?
Steve.


在21/7/04 8:50 pm,在文章BD ****** ***********@127.0.0.1,\"theve,

< ro ** @ 127.0.0.1>写道:
On 21/7/04 8:50 pm, in article BD*****************@127.0.0.1, "Steve"
<ro**@127.0.0.1> wrote:
在21/7/04 8:46 pm,在文章cd**********@chessie.cirr.com,克里斯托弗
Benson-Manica <在*** @ nospam.cyberspace.org>写道:
On 21/7/04 8:46 pm, in article cd**********@chessie.cirr.com, "Christopher
Benson-Manica" <at***@nospam.cyberspace.org> wrote:
我会试着解释一下我想做什么:

我有foo.h和foo.cpp。包含foo.h的单位将定义一个
枚举栏:

枚举栏{typeNone,typeBaz,typeQuux,...,count};

一种方法在foo.cpp中定义的需要返回typeNone。正在使用

static_cast< bar>(0)

可接受?
I''ll try to explain what I want to do:

I have foo.h and foo.cpp. Units that include foo.h will define an
enumeration bar:

enum bar { typeNone, typeBaz, typeQuux, ... , count };

A method defined in foo.cpp needs to return typeNone. Is using

static_cast< bar >( 0 )

acceptable?



我错过了一些明显的东西吗?为什么不返回typeNone?


Am I missing something obvious? Why not just return typeNone?

此外,foo.cpp中的方法需要返回typeBaz,typeQuux等。
有什么方法可以指定这些bar枚举的值是没有实际定义条的(因为包含foo.h的单位会照顾它)?
Also, methods in foo.cpp need to return typeBaz, typeQuux, etc. Is
there any way to specify that these are values of the bar enumeration
without actually defining bar (since units that include foo.h will
take care of that)?



是foo.cpp#包括foo.h?

史蒂夫。


Is foo.cpp #including foo.h?
Steve.



糟糕,对不起,让我再次仔细阅读OP ......


好​​的,让我重新解释一下我的答案...


为什么不把enum声明放在foo.h中?

Steve。


Oops, sorry, let me read the OP again more closely...

OK, let me rephrase my answer...

Why not put the enum declaration in foo.h?
Steve.


Steve< ro ** @ 127.0.0.1>这样说:
Steve <ro**@127.0.0.1> spoke thus:
我错过了一些明显的东西吗?为什么不返回typeNone?
Am I missing something obvious? Why not just return typeNone?




我的意图是foo.h和foo.cpp都不会实际定义bar,

或许类似于


foo.h:


enum bar;


foo.cpp


#include" foo.h"


/ *无论


my_special_unit.cpp:


#include" foo.h"


enum bar {typeNone,typeBaz,count};


some_other_unit.cpp:


#include" foo.h"


enum bar {typeNone,typeQuux,typeCharlie,count};


大概这不会起作用,因为酒吧枚举永远不会充实

for foo.cpp。基本上,我想制作

枚举将使用的符号可用于foo.cpp而不实际定义

枚举。那有意义吗?可能吗?


-

Christopher Benson-Manica |我*应该*知道我在说什么 - 如果我

ataru(at)cyberspace.org |不,我需要知道。火焰欢迎。



My intent is that neither foo.h nor foo.cpp will actually define bar,
perhaps something like

foo.h:

enum bar;

foo.cpp

#include "foo.h"

/* whatever

my_special_unit.cpp:

#include "foo.h"

enum bar { typeNone, typeBaz, count };

some_other_unit.cpp:

#include "foo.h"

enum bar { typeNone, typeQuux, typeCharlie, count };

Presumably this won''t work, since the bar enumeration is never fleshed
out for foo.cpp. Basically, I want to make the symbols that the
enumeration will use available to foo.cpp without actually defining
the enumeration there. Does that make sense? Is it possible?

--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.


这篇关于枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆