I'm supposed to program a game in C++ and OpenGL. I tried to structure it after Unity, so I have Gameobject
s that inherit the Component
s they need. My problem is my renderer. This component contains a shape, Vao, Vbo and a Color. In this constructor I am trying to register the object in my GameView
LineRenderer::LineRenderer(){
shape = { 1.0,1.0,0.0,
1.0,0.0,0.0,
0.0,0.0,0.0,
0.0,1.0,0.0 };
InitializeVertexArrayObject(&VAO, &VBO, shape);
GameView::add(this);
}
The GameView
has a static vector as member:
static std::vector<LineRenderer*> items;
And the add
function just adds the pointer to the vector:
void GameView::add(LineRenderer* item){
items.push_back(item);
}
Now, obviously, this is not working because every time I want to render the objects in the GameView
they no longer exists. Google says this has something to do with the Copy Constructor and it seems the way I want to do this is not possible.
The Question is, is it even possible to inherit from a class that registers itself somewhere else (if the Object is always copied into the variable it's assigned to)? And, if not, what would be the best way to implement behaviour similar to this?
question from:
https://stackoverflow.com/questions/65887106/register-in-constructor-over-inheritance-after-copy-constructor-no-longer-acc 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…