문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top