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

  • Thread starter Thread starter Tau
  • Start date Start date
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!
 
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/
 
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==]
 
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/
 
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==]
 
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==]
 
"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/
 
Does this become a language learning thread?
I mean not the program language but the English language... :-)
 
Back
Top