Equivalent of C# 'as' command in C++? -


In C #, you can use like to change one type or tap. :

  object o = whatever (); String as string s = o;  

Is there a simple easy way to get it into C ++?

I am using Visual Studio 2010, if this is important.

[Update]: It is very important to remember, cast and use as . Casting (at least in C #) will throw an exception if it does not match:

  object o = null; String S = (string) o; // will crash in C ++, it will be a dynamic_cast, if you have a hierarchy where the object is, then  

Parents and strings are children.

  object * p = createMyObject (); String * s = dynamic_cast & lt; String * & gt; (P); If cast (s) {...}  

Cast casting will return a pointer to an indexed object if the artist is possible, or if not, a tap pointer.

In addition, the context of the dynamic casting object of a reference will return if the artist is possible or throw an exception.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -