Too bad static_cast come from C++, it doesn't understand Objective-C classes. You can't even cast from NSString
to NSMutableString
.
What is the syntax for using __bridge cast in conjunction with static_cast?
-
13-10-2022 - |
문제
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?
해결책
제휴하지 않습니다 StackOverflow