我是C++新手,正在從Java代碼移植。我有一個渲染器類,它具有一個將接口作爲參數的方法。這樣調用者可以定義如何渲染其緩衝區。現在,當我嘗試「移植」上課時,我遇到了麻煩。我收到錯誤'分配一個抽象類類型的對象'。這是我的代碼,我想我需要做一些事情的一部分:當該類有嵌套的抽象類時,我該如何分配一個類(使用new)?
// Interface to the OpenGL ES renderer; consumed by GLView
struct IRenderingEngine {
virtual void initialize(int width, int height) = 0;
virtual void render() const = 0;
virtual ~IRenderingEngine() {}
};
class Renderer : public IRenderingEngine
{
public:
...
class IDrawGLBuffer
{
public:
virtual ~IDrawGLBuffer() {};
virtual void function(VBODescription vboDescription,
ShaderDescription shaderDescription);
};
class ShaderDescription
{
public:
ShaderDescription(){};
ShaderDescription(string vertexShaderText,
string fragmentShaderText,
map<string,GLint>& variableMap,
IDrawGLBuffer& callback,
int vertexDimensions);
GLuint getProgramID() const {return shaderProgramID;};
int getVertexDimensions() const {return vertexDimensions;};
friend class Renderer;
private:
string vertexShaderText;
string fragmentShaderText;
GLuint shaderProgramID;
IDrawGLBuffer callback;
int vertexDimensions;
map<string,GLint> variableMap;
};
class VBODescription
{
public:
VBODescription(){};
VBODescription(string shaderName,
map<string, Buffer>& variableMap,
GLenum usage,
int indexTotal,
GLuint textureID);
int getIndexTotal() const {return indexTotal;};
GLuint getTextureID() const {return textureID;};
friend class Renderer;
private:
GLenum usage;
map<string, Buffer> variableMap;
string shaderName;
int indexTotal;
GLuint textureID;
};
...
};
有IRenderingEngine類純虛函數嗎? – Andrey
請發佈完整的代碼。另外請注意,C++嵌套類與Java嵌套類非常不同。沒有存儲在內部類中的外部類的「this」指針。 –
@Joe如果它可能是一個純粹的抽象類。我見過很多。 –