预期的specifier-qualifier-list之前... C ++ / Objective-C iPhone项目中的错误

Dus*_*sda 3 c++ iphone opengl-es objective-c

因此,我正在阅读O'Reilly的iPhone 3D编程书中的第一篇教程。在本教程的这一点上,它将所有OpenGL ES内容拉到一个单独的c ++接口中。据我所知,我已经按照书中的内容来写,但似乎无法弄清楚该编译器错误。我对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() {}
};
Run Code Online (Sandbox Code Playgroud)

我有一个名为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
Run Code Online (Sandbox Code Playgroud)

最后,一个带有准系统实现的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
Run Code Online (Sandbox Code Playgroud)

小智 5

您需要将HelloArrowAppDelegate.m重命名为.mm文件。它在第20页的书中指出(中间有爪子的要点)。我错过了那部分,并且遇到了同样的问题。将文件更改为.mm后,程序开始工作。