The following code compiles fine in one C++ project in RenderingEngine.cpp:
IRenderingEngine* CreateRenderer1()
{
return new RenderingEngine1();
}
but if I start a new project in Xcode 4.3.2, it gives error:
Allocating an object of abstract class type ‘RenderingEngine1’
The definition is in 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() {}
};
How can this be fixed? (this is part of iPhone 3D Programming in its project 1).
Update: in 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;
};
and those 5 functions are all defined. (the last two are dummy — all empty for now)
At a guess, I’d say it depends how you’re using the returned
IRenderingEnginepointer. 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
IRenderingEnginewhich does not have all the required pure virtual implementations.