I'm writing a game engine in C++ for the first time and I need a state manager / machine. I want it to have ownership of all states.
When I started digging into how functions usually work, I found out they normally copy or move a value into the function. That seems unnecessary to me.
What I want is to create the value temporarily elsewhere, pass it to the function, and have it be constructed in the state machine's memory, so to speak, without moving or copying that value. Is this possible? And is it practical?
It would look like this:
class StateManager {
public:
StateManager(State state) {
this.state = state; // Magically have this.state be the passed state, without copying or moving the constructed state. I think it's called "In place construction"?
}
private:
State state;
}
void main() {
State state(12, 8); // Create an object with some parameters
state.initialize(); // Maybe perform a few things on it
StateManager states(state);
}