C ++ 11 auto type withdrawal of inference rules, constants and volatile determinants. However, you can ask the C ++ compiler to use decltype type inference rules to preserve all of these qualifiers for declaring a variable type. In your case, it could be:
decltype(auto) x = testClass.GetFoo();
But this code can cause some side effects, such as a reference to the destroyed object, so you need to keep in mind the actual type of the variable and the lifetime.
source share