In another topic someone suggested using
auto x = f();
instead of
T x = f();
(if the signature of f
is T f()
). They pointed out this prevents silent object slicing if someone happens to change f
to U f()
, where U
descends from T
.
It makes sense to me, but there might be other things in play that I am missing. So, which is better and why?