It is bad to return a pointer to a local variable from a function, because the pointer will be dangling when the function returns.
It is ok to return a const reference to a const defined in a function, because the compiler will ensure the lifetime of the const will be at least as long as the lifetime of the const reference.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment