How should the below member function prototype be interpreted in C++11?
class C {
public:
auto f(...) -> T const;
}
It would seem to me that it could either be a const member function of the class C, or a non-const member function which returns a const value of type T.
I know I could just write the function as
T const f(...);
or
T f(...) const;
However, I want to be consistent with how I declare functions, so I decided to use the new C++11 auto f(...) -> RetType
way everywhere.
The trailing-return-type comes after cv- and ref-qualifiers of a non-static member function. This means the example in the question is the same as T const f(...);
.
§8.4.1 [dcl.fct.def.general] p2
The declarator in a function-definition shall have the form
D1
( parameter-declaration-clause ) cv-qualifier-seqopt ref-qualifieropt exception-specificationopt attribute-specifier-seqopt trailing-return-typeopt
To declare a const
member function, you'd write auto f(...) const -> T const;
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With