c++ - 预期的说明符限定符列表之前... C++/Objective-C iPhone 项目中的错误

标签 c++ iphone objective-c opengl-es

所以我正在阅读 O'Reilly 的 iPhone 3D 编程书中的第一个教程。在本教程的这一点上,它将所有 OpenGL ES 的东西拉到一个单独的 c++ 接口(interface)中。据我所知,我已经完全按照这本书的要求去做了,但我似乎无法弄清楚这个编译器错误。我是 C++ 的新手(过去主要是 C#),所以我确信这是愚蠢的。

以下是所有相关文件的当前状态。

我有一个名为 IRenderingEngine.hpp 的 C++ 头文件,其中包含以下内容:

enum DeviceOrientation {
    Unknown,
    Portrait,
    PortraitUpsideDown,
    LandscapeLeft,
    LandscapeRight,
    FaceUp,
    FaceDown,
};

struct IRenderingEngine* CreateRenderer1();

struct IRenderingEngine {
    virtual void Initialize(int width, int height) = 0; //Compiler error "expected specifier-qualifier-list before 'virtual'
    virtual void Render() const = 0;
    virtual void UpdateAnimation(float timeStep) = 0;
    virtual void OnRotate(DeviceOrientation newOrientation) = 0;
    virtual ~IRenderingEngine() {}
};

我有一个名为 GLView.h 的 objective-c/c++ 头文件,如下所示:

#import "IRenderingEngine.hpp"
#import <OpenGLES/EAGL.h>
#import <QuartzCore/QuartzCore.h>

@interface GLView : UIView {
    EAGLContext* m_context;
    IRenderingEngine* m_renderingEngine; //Compiler error: Expected specifier-qualifier-list before "IRenderingEngine"
    float m_timeStamp;
}

- (void) drawView: (CADisplayLink*) displayLink;
- (void) didRotate: (NSNotification*) notification;

@end

最后,一个包含基本实现的 GLView.mm 文件:

#import "GLView.h"


@implementation GLView

+ (Class) layerClass
{
    return [CAEAGLLayer class];
}

- (id)initWithFrame:(CGRect)frame {
    return self;
}

- (void) drawView:(CADisplayLink *)displayLink
{

}

-(void) didRotate:(NSNotification *)notification
{

}

@end

最佳答案

您需要将 HelloArrowAppDelegate.m 重命名为 .mm 文件。它在书中第 20 页(带有爪子要点的中间部分)中说明。我错过了那个部分并且遇到了同样的问题。将文件更改为 .mm 后,程序运行正常。

关于c++ - 预期的说明符限定符列表之前... C++/Objective-C iPhone 项目中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3088919/

相关文章:

iphone - 如何检测两根手指的轻弹

iphone - 我有一个代表 coredata 的类——我如何添加一个 getter?

ios - 如何为键设置 iOS 默认可本地化字符串?

objective-c - 如何从 Swift 执行外部程序?

iphone - NSString 中的原始字节使用什么编码

ios - Xcode 错误 "Can' t 安装应用程序 ... [appname].app 需要 [devicename] 不支持的 "z"功能

c++ - 是否有基于宏的适配器来从类中创建仿函数?

c++ - 为什么此用户定义的转换失败?

c++ - 重载以结构继承作为参数的函数 C++

c++ - 迷宫最少转弯次数