[C++] decltype(auto) C++ 11 feature
1 //C++ 11 feature
2 template <class T1, class T2>
3 auto getMultiply(T1 data1, T2 data2) -> decltype(data1*data2)
4 {
5 return data1*data2;
6 }
7 int main()
8 {
9 //cout << getResult<int>(3,3,4,5) << endl;
10 cout <<getMultiply(12.2, 13.3)<< endl;
11 cout << typeid(getMultiply(12.2, 13.3)).name() << endl;
12 system("pause");
13 }
- auto : Deduce the type of data based on actual data
- auto is not allowed to be used as a function parameter