This code is incorrect and dangerous, as it returns a reference to a member of mdValueOut . The object is destroyed before exiting the function, thus, the reference to its member is dangling.
There are two possible solutions to the problem:
Return the member by value (expensive when the object is a std::vector or a std::string)
This code is incorrect and dangerous, as it returns a reference to a member of
mdValueOut
. The object is destroyed before exiting the function, thus, the reference to its member is dangling.There are two possible solutions to the problem:
std::vector
or astd::string
)getValue(const MDLabel label, T &valueOut, size_t id)
overload, which is currently deprecated (but widely used in the xmipp codebase).