[英]Old c++/objective-c++ project no longer complies code that stores UIKit objects in stl containers "Cast of a non-Objective-C pointer type ... UITouch"
所以我构建了这个设计为跨平台的引擎。 很久以前,我有大量的多点触控自定义处理,UIKit 为引擎所用的游戏提供帮助。
为此,我引入了 PlatformTouchManager 的设计(这个 c++ class 具有处理所有内容的引擎结构,并将其转换为向量中的普通老式 c 结构。
然后对于每个平台都有一个 class 是一个子类objective-c++ class iOSMultiTouch: public PlatformTouchManager {
它将处理 UIKit 对象并调用和修改超类上的东西以保持其引擎级多点触控 state 正确的想法。
现在在这个 PlatformTouchManager (objective-c++) 中,我有相当多的代码将 UIKit objective-c 个对象放入 STL 个容器中,例如
std::set<std::shared_ptr<UITouch*>> downSet;
std::vector<std::shared_ptr<UITouch*>> fingerList;
void iOSMultiTouch::touchesDown(NSSet* set) {
for (UITouch* t in set) {
std::shared_ptr<UITouch*> sptr = std::make_shared<UITouch*>(t);
if (downSet.find(sptr) == downSet.end()) {
downSet.insert(sptr);
}
}
}
我不知道这是否是一个坏主意,但它在 这个项目编译中已经工作了多年。
现在突然间我收到了这个错误/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.2.sdk/usr/include/c++/v1/memory:2684:27: Cast of a non-Objective-C pointer type 'typename _CompressedPair::_Base2 *' (aka '__compressed_pair_elem<UITouch *__strong, 1> *') to 'UITouch *__strong *' is disallowed with ARC
它的责任下降了很多堆栈(进入 STL 并进入我的代码)进入这一行std::shared_ptr<UITouch*> sptr = std::make_shared<UITouch*>(t);
是否需要添加某种注释来帮助此代码工作和编译? 也许这样做完全是个坏主意?
I think the reason I did the class this way was that I thought I needed the class defined in objective-c++ code to be a c++ class to fit in and that that c++ class object in the header couldn't use objective-c things.
它告诉您您有一个指向__compressed_pair_elem
的指针,它不是 Objective-C object,并将其转换为指向 Objective-C object 的指针,这是 ARC 不允许的,它不知道如何处理结果。
在 C++ 代码中使用的正确类型是id
:
std::set<std::shared_ptr<id __strong>> downSet;
std::vector<std::shared_ptr<id __strong>> fingerList;
void iOSMultiTouch::touchesDown(NSSet* set) {
for (UITouch* t in set) {
std::shared_ptr<id __strong> sptr = std::make_shared<id __strong>(t);
if (downSet.find(sptr) == downSet.end()) {
downSet.insert(sptr);
}
}
}
附言。
不确定我是否正确,我现在无法访问 Xcode。
for (UITouch* t in set)
可能不正确,应该是for (UITouch* t: set)
。__strong
在声明中可能很奇怪,可能会被省略。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.