How is it inefficient? Do you mean in this comparison?
Originally Posted by Elysia
object *p = get_first_object();
// use p
p = get_second_object();
// use p
Because any compiler with even a primitive flow analysis will just reuse the same storage space for the second reference if r1 isn't used anymore after r2 is assigned. And if it is, it still works, whereas the pointer reassign snippet just misbehaves.
object &r1 = get_first_object();
// use r1
object &r2 = get_second_object();
// use r2
I still don't see the connection to OO.
Never has been for me. Since I use OO a lot, I need classes that keeps track of other classes, and that means pointers.
That's exactly their weakness. Or rather, that's what makes them a low-level component that should be used to build high-level components (smart pointers, containers) that are then used in high-level code.
And in any case, that's just one case usage scenario. Where pointers can be used for many more.
If we always stick to the way we already do it, how do we get better? The nice thing about this forum is that you can discuss the relative merit of various approaches.
...But I tire of this. Everyone has their own way of coding and we should stick to that.
There's no universal best way. There definitely are good and bad ways. For example, not using RAII and using endless try...catch blocks in an attempt to make code exception-safe would be a bad way. (Not that I'm accusing you of doing that. It's just an example that springs to mind whenever I read about raw pointers.)
There's really no good or bad way.