"C++ Programming Language Fourth Edition" Chapter 12.1.4
The post-return type puts the return value behind when declaring/defining the function
auto getValue(int value)->int
{
return value*2;
}
This usage is mainly used in templates, which sometimes cannot determine the return value type:
template<class T1,class T2>
auto getValue(T1 v1,T2 v2)->decltype (v1 + v2)
{
return v1 + v2;
}
#define debug qDebug()<<
int main(int argc, char *argv[])
{
debug getValue<int,int>(7,5.5);
debug getValue<int,double>(7,5.5);
}
If this function is passed in two ints, the return value type is int, and if one int and a double are passed in, the return value type is double.