我正在做一个只需要重写的项目,但在这一点上不是一个选择。
我有一个C++函数,它被调用并执行所有类型的操作。我需要它来读取App Delegate类中的变量。
例如,我有:
@interface MyAppDelegate : NSObject <UIApplicationDelegate>
{
UIWindow *window;
MyViewController *viewController;
int mToleranceLevel;
}然后我有一个需要访问mToleranceLevel的函数:
bool FindExtrinsics(...)
{
float maxError = mainDelegate.mMaxError;
...
}问题是,这是这样声明的:
@interface MyClass : UIViewController
{
...
}
@properties ...
bool FindExtrinsics(...);
@end那么我如何从AppDelegate类中获取一个值呢?我知道如何获得当前的委托:
mainDelegate = (RedStripeARAppDelegate *)[[UIApplication sharedApplication] delegate];但是如何使用这些信息来获取C++函数中的值呢?有没有办法创建一个静态变量,这样我就可以调用MyAppDelegate.mToleranceValue;??
发布于 2010-09-28 05:06:42
Xcode支持Objective-C++,这使您能够从C++代码中使用Objective-C调用。将C++代码文件的扩展名从.cpp (或.cc)更改为.mm,您将能够从C++代码中获得值,就像从Objective-C代码中一样。
https://stackoverflow.com/questions/3807857
复制相似问题