通过将其他对象复制到新类来创建新类时,我遇到了一些问题。据我所知,下面的代码可以工作,但是我的编译器指出它缺少类材料的默认构造函数。据我所知,这不是必需的。我在这里做错了吗?
第一类构造函数:
shadingBatch::shadingBatch(const vertexAttribLayout& layout, const material& batchMaterial){
dataFormat_ = layout;
batchMaterial_ = *(new material(batchMaterial));
}
我也试过
shadingBatch::shadingBatch(const vertexAttribLayout& layout, const material& batchMaterial){
dataFormat_ = layout;
batchMaterial_ = batchMaterial;
}
但是会返回相同的编译器错误。
二等定义
class material {
protected:
shader shader_;
public:
material (const shader* shaderProgram);
material (const material&);
~material();
void compileShader();
} ;
第二类复制构造函数
material::material(const material& other){
shader_ = *(new shader(other.shader_));
}
编辑:根据要求,
一级定义
class shadingBatch {
friend class cheeseRenderer;
protected:
std::vector<primitive*> primitives_;
std::vector<vertex> vertices_;
std::vector<GLuint> elements_;
vertexAttribLayout dataFormat_;
material batchMaterial_;
GLuint VAO_;
GLuint VBO_;
GLuint EBO_;
public:
~shadingBatch();
GLuint updateBatch (void);
void addPrimitive (primitive*);
shadingBatch(const vertexAttribLayout&, const material&);
private:
void updatePrimitives (void);
void setVertexAttributes(void);
} ;
以及调用构造函数的位置:
shader* defaultShader = new shader(fragmentSource,vertexSource);
material* defaultMaterial = new material(defaultShader);
vertexAttribLayout* defaultVertexData = new vertexAttribLayout();
shadingBatch* batch = new shadingBatch(*defaultVertexData,*defaultMaterial);
cheeseRenderer renderer(*batch);