代码之家  ›  专栏  ›  技术社区  ›  Dusda

在C++或Objtovi-C iPhone项目中错误之前的期望说明符限定列表

  •  2
  • Dusda  · 技术社区  · 16 年前

    所以我要学习O'Reilly的iPhone3D编程书中的第一个教程。在本教程的这一点上,它将所有opengles内容拉入一个单独的c++接口。据我所知,我已经把这本书看完了,但我似乎还没弄明白这个编译器错误。对于C++,我是相当新的(过去大部分是C),所以我肯定这是很愚蠢的。

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

    我有一个名为 IRenderingEngine.hpp公司 包括以下内容:

    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() {}
    };
    

    我有一个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
    

    最后,一个 使用裸体实现的文件:

    #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
    
    6 回复  |  直到 16 年前
        1
  •  3
  •   Georg Fritzsche    16 年前

    这个错误消息例如发生在如果两个头中的一个被包含在一个纯ObjuleC源文件中,它不知道处理C++代码的任何内容。

    允许 GLView 要从普通ObjuleC源使用,只使用渲染引擎的前向声明,不包括C++头 GLView.h

    // GLView.h:
    struct IRenderingEngine;
    @interface GLView : UIView {
        struct IRenderingEngine* m_renderingEngine;
    // ...
    @end
    
    // GLView.mm:
    #import "IRenderingEngine.hpp"
    // ... etc.
    

    或者,您可以使用不透明指针来包装C++实例,以保持Objto-C接口更稳定,例如Rob Napiers post 关于这个问题。

    当这个问题解决后,您仍然需要解决 CreateRenderer1() struct IRenderingEngine; 在函数之前或只是在函数的定义之后移动它 struct

        2
  •  5
  •   Kelvin    16 年前

    您需要将HelloArrowAppDelegate.m重命名为.mm文件。它在书的第20页(中间部分用爪子的圆点)上说。我错过了那个部分,也有同样的问题。把文件改成.mm后,程序运行了。

        3
  •  1
  •   JimboUK    15 年前

    我也有同样的问题。原来是因为在Xcode的Groups&中将HelloArrowAppDelegate.m重命名为HelloArrowAppDelegate.mm;文件实际上没有重命名文件!有一次我用Finder把它改名为project。注意:当您再次打开项目时,Xcode可能会抱怨缺少HelloArrowAppDelegate.m,只需右键单击它,删除它,然后使用“添加现有文件”将HelloArrowAppDelegate.mm文件添加回。

        4
  •  1
  •   Mike    14 年前

    这似乎是一个逃避,但我有完全相同的问题,当我更新到Xcode4.x

        5
  •  0
  •   fbrereto    16 年前

    线路

    struct IRenderingEngine* CreateRenderer1();
    

    必须在 IRenderingEngine 班级(另外,如果要将变量用作指向该结构类型的指针,则应省略其声明中的括号。)

    对于你的另一个错误,我想你应该用 struct .

        6
  •  0
  •   Cogwheel    16 年前

    我认为这条线是导致错误的原因:

    struct IRenderingEngine* CreateRenderer1();