I'm working on a small component based game engine in C++. Various components are added to an internal list of a gameobject object, to save some time I don't make a member variable of these components, only the game object is a member variable, like so:
MeshComponent* meshRenderer = new MeshComponent(mesh, material);
First of all, I suggest you to study C++ more before starting big projects like game engine.
What goes out of scope is the
meshRenderer variable that is of type
MeshComponent*, that is pointer to
MeshComponent. What happens when pointer goes out of scope? Nothing at all. The memory was allocated on heap using the
new operator and it will stay there until you deallocate it using