1

次のコードは、次の1つのC++プロジェクトで正常にコンパイルされRenderingEngine.cppます。

IRenderingEngine* CreateRenderer1()
{
    return new RenderingEngine1();
}

しかし、Xcode 4.3.2で新しいプロジェクトを開始すると、エラーが発生します。

抽象クラスタイプ'RenderingEngine1'のオブジェクトの割り当て

定義はにありますIRenderingEngine.hpp

struct IRenderingEngine {
    virtual void Initialize(int width, int height) = 0;    
    virtual void Render() const = 0;
    virtual void UpdateAnimation(float timeStep) = 0;
    virtual void OnRotate(DeviceOrientation newOrientation) = 0;
    virtual ~IRenderingEngine() {}
};

これはどのように修正できますか?(これは、プロジェクト1のiPhone 3Dプログラミングの一部です)。

更新:でRenderingEngine.cpp

public:
    RenderingEngine1();
    void Initialize(int width, int height);
    void Render() const;
    void UpdateAnimation(float timeStep);
    void onRotate(DeviceOrientation newOrientation);

private:
    GLuint m_framebuffer;
    GLuint m_renderbuffer;

};

そしてそれらの5つの機能はすべて定義されています。(最後の2つはダミーです-今のところすべて空です)

4

3 に答える 3

3

At a guess, I'd say it depends how you're using the returned IRenderingEngine pointer. As the project compiles in one project, you must have implemented all the necessary pure virtual functions from the base class. In the failing compilation, you must be missing an implementation or two.

Why it compiles in the 'book' example, but not your example is difficult to say with the information you've given. I would check through the build output to ensure that the source files you are compiling (header and implementation for both classes) are exactly the ones you think that they are. It's possible you are picking up another version of IRenderingEngine which does not have all the required pure virtual implementations.

于 2012-05-17T08:45:20.023 に答える
1

これは、すべての純粋な仮想ベースメソッドの実装を提供することで修正できます。

RenderingEngine1から継承すると思いIRenderingEngineます。したがって、オーバーライドして実装します

virtual void Initialize(int width, int height) = 0;    
virtual void Render() const = 0;
virtual void UpdateAnimation(float timeStep) = 0;
virtual void OnRotate(DeviceOrientation newOrientation) = 0;
于 2012-05-17T08:22:49.277 に答える
1

その最初の章を読んでいる間、私は同じ問題に直面しました。とてもイライラしました。

右側にある赤いエラーメッセージをクリックすると、次のように表示されることがわかりました。

抽象クラス型のオブジェクトを割り当てる...

XcodeはそのIRenderingEngine.hppファイルに直接切り替えて、問題が灰色で何であるかを示します。

于 2012-10-26T05:24:35.443 に答える