[英]Why do we define C++ types as void for the Objective-C compiler in LLVM (while it is okay for the C++ compiler to see objective-C interfaces)?
I was going through the source of an iOS project that uses a C++ library when I stumbled upon this few rather interesting lines of code in the header file of a Objective-C wrapper for C++:当我在 C++ 的 Objective-C 包装器的头文件中偶然发现这几行相当有趣的代码行时,我正在浏览一个使用 C++ 库的 iOS 项目的源代码:
#ifdef __OBJC__
#ifndef __cplusplus
typedef void VisageTracker;
typedef void FaceData;
typedef void DemoFrameGrabber;
typedef void FDP;
typedef void VsImage;
#endif
#endif
@interface TrackerWrapper : NSObject {
CustomGLView *glView;
#ifdef __cplusplus
VisageSDK::VisageTracker* tracker;
VisageSDK::FaceData trackingData;
DemoFrameGrabber *demoFrameGrabber;
DemoObserver *demoObserver;
int glWidth;
int glHeight;
bool inGetTrackingResults;
#endif
}
A question immediately hit me: Why are all the C++ types such as VisageTracker, FaceData, DemoFrameGrabber, FDP, VsImage
being defined as void
for the Objective-C compiler?我立刻VisageTracker, FaceData, DemoFrameGrabber, FDP, VsImage
一个问题:为什么所有的 C++ 类型,如VisageTracker, FaceData, DemoFrameGrabber, FDP, VsImage
被 Objective-C 编译器定义为void
?
I'm quite curious as how LLVM does the compilation here.我很好奇 LLVM 是如何在这里进行编译的。 It appears that the header file would be gone through twice, once by a C++ compiler and once by a Objective-C compiler.头文件似乎会经过两次,一次由 C++ 编译器处理,一次由 Objective-C 编译器处理。
Question: why must we hide the C++ types from the Objective-C compiler, but the C++ compiler is okay seeing an objective-C interface (and not only that but we can also "inject" C++ stuff into the interface)?问题:为什么我们必须对 Objective-C 编译器隐藏 C++ 类型,但 C++ 编译器可以看到 Objective-C 接口(不仅如此,我们还可以将 C++ 的东西“注入”接口中)?
I tried removing these lines我尝试删除这些行
#ifdef __OBJC__
#ifndef __cplusplus
typedef void VisageTracker;
typedef void FaceData;
typedef void DemoFrameGrabber;
typedef void FDP;
typedef void VsImage;
#endif
#endif
after which the code didn't fail to compile: it appears to work just fine without these lines.之后代码并没有无法编译:它似乎没有这些行就可以正常工作。 Therefore I conclude that these lines are probably there because因此我得出结论,这些线可能在那里,因为
or/and或/和
Because C++
and Objective-C
is different languages.因为C++
和Objective-C
是不同的语言。 They can be used both only in Objective-C++
.它们只能在Objective-C++
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.