how to know an int is the member of an enum type?(C++/CLI)

T

Tau

for example:
enum class SomeEnumType
{
A1 = 1;
A2 = 2;
A3 = 3;
};


how to write a function like:
bool isOneOfSomeEnumType(int i)? (in C++/CLI)

isOneOfSomeEnumType(1) will return true
isOneOfSomeEnumType(2) will return true
isOneOfSomeEnumType(4) will return false

somebody helps me! Thanks!
 
J

Jochen Kalmbach [MVP]

Hi Tau!
for example:
enum class SomeEnumType
{
A1 = 1;
A2 = 2;
A3 = 3;
};


how to write a function like:
bool isOneOfSomeEnumType(int i)? (in C++/CLI)

return System::Enum::IsDefined(SomeEnumType::typeid, i);


--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
P

Peter Oliphant

return System::Enum::IsDefined(SomeEnumType::typeid, i);

What exactly is 'typeid' here? Only thing I could find suggests I would need
an existing variable of SomeEnumType type to do a GetType() and get this
'typeid'. Put another way, does it takes one to know one? ; )

[==P==]
 
J

Jochen Kalmbach [MVP]

Hi Peter!
What exactly is 'typeid' here? Only thing I could find suggests I would need
an existing variable of SomeEnumType type to do a GetType() and get this
'typeid'.

I C# the equivalent is "typeof(SomeEnumType)"...

See also:
http://msdn2.microsoft.com/en-us/library/ms235260.aspx
http://msdn2.microsoft.com/en-us/library/kwd9abya.aspx

For "typeid" you do not need to have a instance of the object....

Put another way, does it takes one to know one? ; )

I don´t understand...


--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
P

Peter Oliphant

Put another way, does it takes one to know one? ; )
Sorry, a bad attempt at humor. There is a saying "it takes one to know one".
In this context, if it was required to create an instance of an object type
in order to identify if another object is of the same type, I felt the
saying was somewhat appropriate and therefore kinda humerous. As you've
explained, however, this is not necessary, so the statement is not so funny
anymore....hehe

[==P==]
 
P

Peter Oliphant

For someone who's 'english is not their native language' you communicate in
English a lot better than some people I know for whom 'english IS their
native language'... ; )

[==P==]
 
B

Ben Voigt

"Peter Oliphant" wrote in message
Sorry, a bad attempt at humor. There is a saying "it takes one to know
one".

The most common usage is in response to being called an idiot, newbie, or
other derogatory term. See also: "It takes a thief to catch a thief"
In this context, if it was required to create an instance of an object
type in order to identify if another object is of the same type, I felt
the saying was somewhat appropriate and therefore kinda humerous. As
you've explained, however, this is not necessary, so the statement is not
so funny anymore....hehe

[==P==]

Jochen Kalmbach said:
Hi Peter!

I C# the equivalent is "typeof(SomeEnumType)"...

See also:
http://msdn2.microsoft.com/en-us/library/ms235260.aspx
http://msdn2.microsoft.com/en-us/library/kwd9abya.aspx

For "typeid" you do not need to have a instance of the object....



I don´t understand...


--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
T

Tau

Does this become a language learning thread?
I mean not the program language but the English language... :)
 

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

Top