2
Bimpfi
3y

We have a C++ for embedded systems training at work this week.
References are a good thing but after looking for the reason why one object has no reference to the other for half of an hour just to realise that my member wasn't a reference so that i got an copy gave me the urge to use pointers instead. But unfortunately we'd to use a reference in this simple exercise which cost me a lot of time because that damn reference.

Comments
  • 0
    You should either use smart pointers or copy. References as member variables are undesirable for several reasons.

    The most obvious is that you can't have an assignment operator.

    Also references don't manage object lifetime so if the thing you have a reference to is destroyed you cannot use it but have no way of knowing.
  • 0
    Is there a reason you want a reference instead of a copy?
Add Comment