If the constructor for Door
looks like this:
Door::Door(Doorknob doorknob) : m_doorknob(doorknob) { }
Then you would instantiate a Door
like this:
Doorknob doorknob;
Door door(doorknob); // Does an object copy of doorknob occur here?
It seems like if you store Doorknob
as a pointer, you can explicitly avoid the copy:
Door::Door(Doorknob * doorknob_ptr) : m_doorknob_ptr(doorknob_ptr) { }
Instantiate Door
like this:
Door door(new Doorknob);
But now you have to make sure to delete doorknob
inside Door
's destructor, which seems ugly.
What is the preferred approach?