Problem
Basically I am just looking for a text replacement for a object which i have to access through a nested structure so I don't have this long lines.
Camera cam = clients_manager.network_controlled_simulations[simulation_index].simulation.agents[agent_index].cameras[camera_index];
cam.do_stuff();
However this creates a copy of the Camera object. Which in turn crashes my program further down the line. Which is not the behaviour I want. I don't want a copy i just want to avoid this long lines and have readable code.
Things i've tried
1.
One way which would work:
Camera *cam = &clients_manager.network_controlled_simulations[simulation_index].simulation.agents[agent_index].cameras[camera_index];
(*cam).do_stuff();
But then everytime i want to use a method or property I have to do (*cam).property and (*cam).method()
I'd prefer accessing it like:
cam.property
2.
So i thought I would do:
Camera cam;
*cam = &clients_manager.network_controlled_simulations[simulation_index].simulation.agents[agent_index].cameras[camera_index];
Which gives me the error:
No operator "*" matches these operands
Operand types are: * Camera
3.
Then Well let's try address operator & :
Camera cam;
&cam = &clients_manager.network_controlled_simulations[simulation_index].simulation.agents[agent_index].cameras[camera_index];
which gives me another error:
expression must be a modifiable lvalue
Question
Is there any way to achieve what I want or should I just settle with the solution i found ?