다른 개체를 복사하여 새 클래스를 만드는 데 약간의 문제가 있습니다. 내가 볼 수있는, 아래의 코드는 작동하지만, 내 컴파일러는 클래스 생성자의 기본 생성자가 누락되었습니다. 내가 볼 수있는 것에서 이것은 필요하지 않습니다. 내가 여기서 뭐 잘못하고 있니?C++ 생성자를 통해 개체 복사
먼저 클래스 생성자 :
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);
오류 메시지를 추가하십시오. 기본 생성자를 놓친 경우 컴파일러가 true 인 시간은 99.999999 %입니다. 하나의 클래스가 누락 된 기본 생성자 클래스를 멤버로 가지며 클래스의 해당 멤버를 올바르게 초기화하지 않는 것이 일반적입니다. –
'shadingBatch' 정의와 그 생성자에 대한 호출을 보여줄 수 있습니까? –
정말 필요하지 않으면 무엇을하고 있는지 알지 못하면'new'를 사용하지 마십시오. 현재 문제와 리소스 누출의 원인이되고 있습니다. – juanchopanza