[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 }
  • autoDeduce the type of data based on actual data
  • auto is not allowed  to be used  as a function parameter
posted @ 2015-10-27 13:22  Jonas0608  阅读(144)  评论(0编辑  收藏  举报