sja*_*a26 3 xcode objective-c++
我正在按照书中的教程(iPhone 3D编程)进行操作,该教程使用:
包含一个示例Xcode项目,可以成功编译.
在我找到示例项目之前,我已经手动输入了本书中的代码,但我收到以下详细文件的以下编译错误:
IRenderingEngine.hpp(Xcode文件检查器 - 文件类型="默认 - C++标题")
...
struct IRenderingEngine {
virtual void Initialize(int width, int height) = 0; //2 errors as marked above
virtual void Render() const = 0; //2 errors as marked above
virtual void UpdateAnimation(float timeStep) = 0; //2 errors as marked above
virtual void OnRotate(DeviceOrientation newOrientation) = 0; //2 errors as marked above
virtual ~IRenderingEngine() {} //2 errors as marked above
};
...
Run Code Online (Sandbox Code Playgroud)
GLView.h(Xcode文件检查器 - 文件类型="默认 - C标头")
#import "IRenderingEngine.hpp"
#import <QuartzCore/QuartzCore.h>
@interface GLView : UIView {
@private
EAGLContext* m_context;
IRenderingEngine* m_renderingEngine; //1 error marked above
float m_timestamp;
}
- (void) drawView:(CADisplayLink*)displayLink;
- (void) didRotate:(NSNotification*)notification;
@end
Run Code Online (Sandbox Code Playgroud)
所有其他文件的文件类型也默认为Xcode文件检查器中的预期文件类型,因此应该可以正常使用构建设置 - Apple LLVM编译器4.2 - 语言 - "根据文件类型编译源代码" - 这与成功编译的示例项目中的Build Setting相同.
由于某些奇怪的原因,在我手动创建的项目中将构建设置更改为"编译源代码为As = Objective-C++",删除了编译错误,应用程序按预期运行.
任何人都可以提供一个理由,为什么这个设置在看似相同(源代码方面)项目之间不一致?
Tom*_*mmy 10
头文件未编译.头文件由预处理器使用 - 只要您将原始文本#include或#import原始文本视为已复制并粘贴到原始文本中.
因此,无论您的文件是.hpp,.h还是其他任何内容都无关紧要.如果.m文件导入包含.hpp文件的.h文件,则.hpp代码将编译为.m文件的一部分,即作为Objective-C.
因此,我猜你已经有了GLView.m.如果要导入.hpp文件,无论是直接还是间接,都需要编译为Objective-C++.一种方法是重命名.mm,另一种方法是告诉项目不要试图通过文件扩展名来猜测语言类型.
| 归档时间: |
|
| 查看次数: |
6925 次 |
| 最近记录: |