Pregunta

I tried below, but compiler does not understand it:

//Foo.mm
id anObjOfTypeFoo;
Foo* obj = (Foo*) anObjOfTypeFoo; //ERROR: must use __bridge

Foo* obj = (__bridge Foo*) anObjOfTypeFoo; //OKAY

Foo* obj = static_cast<__bridge Foo*> (anObjOfTypeFoo); //ERROR

Foo* obj = __bridge (static_cast<Foo*> (anObjOfTypeFoo)); //ERROR

Since Objective-C code is effectively compiled by a C++ compiler for a .mm compilation unit, it should really not have problems to bridge the casts of C++. Can someone shed light on this please?

¿Fue útil?

Solución

Too bad static_cast come from C++, it doesn't understand Objective-C classes. You can't even cast from NSString to NSMutableString.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top