Originally Posted by
CornedBee
Nothing, really. You just have to remember that, once you have a reference member, several things happen. First, you don't get a generated copy assignment operator. Second, the class is no longer a POD, even if it would have been otherwise. Third, if the reference can refer to different objects in different instances, you cannot implement a reliable assignment operator or a reliable swap, because the functions would have to fail for objects coming - in your example - from different worlds. Built-in xenophobia
So when I said that references make poor class members, I was referring to the fact that having a reference member affects the design of the class.
Ah, understood. So what do you prefer for saving an argument taken by const reference as class member, if you want to get a (relyable) copy/assignment operator?
Code:
class Entity
{
Entity(const World& _world)
:m_world(_world)
// or
:msp_world(&_world)
{}
World m_world; // initiate (probably complex) copying
// or
const shared_ptr<World> msp_world;
};