Under C# it is possible to feed strings to the switch() statement and its cases, this doesn't seem to work in C++/CLI. Is there a way to make it work, which I don't know about, or don't I get around chaining if-statements
If you want to get really fancy, you can wrap this in a class so you won't need the trailing ( ) in strswitch[ GetArg( ) ] ( ), and/or pass the string argument to the called function if a map entry is initialized with a boost::function<void(string)>
Without boost, you could use a void(*)( ) in the map.
C++/CLI, Strings and switch()
citifortune concepts
Sree Prakash
Sorry,
--
Boris Jabes, Visual C++ Team
This post is provided "AS IS" and confers no rights
eric963258741
like
std::map< std:
strswitch["Foo"] = &foo;
strswitch["Bar"] = bind(MyBarObj, &CMyBar:
...
strswitch[ GetArg( ) ] ( );
If you want to get really fancy, you can wrap this in a class so you won't need
the trailing ( ) in strswitch[ GetArg( ) ] ( ), and/or pass the string argument to
the called function if a map entry is initialized with a boost::function<void(string)>
Without boost, you could use a void(*)( ) in the map.
Regards,
Michiel Salters
Holywhippet
So you could probably do the same in C++/CLI.