enum escaping keywords

P

Philipp Kraus

Hello,

I create a enum type with language codes like:
enum lang {
en,
it,
de,
asm,
or
}

but some codes are keywords (asm, or). How can I escape them, so that I
can use them like
lang::eek:r or lang::asm ?

Thanks

Phil
 
B

Balog Pal

Philipp Kraus said:
I create a enum type with language codes like:
enum lang {
en,
it,
de,
asm,
or
}

but some codes are keywords (asm, or). How can I escape them, so that I
can use them like
lang::eek:r or lang::asm ?

Those are reserved words. You can not use them as identifiers. chose a
different form like Asm, asm_, l_asm, ...
 
P

Philipp Kraus

Those are reserved words. You can not use them as identifiers. chose a
different form like Asm, asm_, l_asm, ...

Is there no other solution !? Because the language codes are defined in
the ISO 639, so I would like to use the defined
codes as a enum value. I wouldn't create a own value

Thx

Phil
 
V

Victor Bazarov

Is there no other solution !?

Because the language codes are defined in
the ISO 639, so I would like to use the defined
codes as a enum value. I wouldn't create a own value

<shrug again> I would like my variables to be named 'new', 'delete',
and 'for'. I can't, however. So?

V
 
J

James Kanze

I create a enum type with language codes like:
enum lang {
en,
it,
de,
asm,
or
}
but some codes are keywords (asm, or). How can I escape them, so that I
can use them like
lang::eek:r or lang::asm ?

You can't. Note too that enum's don't introduce a new scope (at
least not in current C++), your enum introduces the keywords in
global scope.

The traditional solution to this is to use a simple prefix:

enum lang {
lang_en,
lang_it,
lang_de,
lang_asm,
lang_or
};

or something like that.
 
J

James

Philipp Kraus said:
Hello,

I create a enum type with language codes like:
enum lang {
en,
it,
de,
asm,
or
}

but some codes are keywords (asm, or). How can I escape them, so that I
can use them like
lang::eek:r or lang::asm ?


struct lang {
enum instruction {
EN,
IT,
DE,
ASM,
OR
};
};


?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
DewittMill
Top