
正文
c++11 追踪返回类型
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
c++11 追踪返回类型
返回类型后置:使用"->"符号,在函数名和参数列表后面指定返回类型。
#define _CRT_SECURE_NO_WARNINGS#include <iostream>
#include <string>
#include <vector>
#include <map>int func(int, int);
auto func2(int, int)->int; // 指定返回类型template<typename T1, typename T2>
auto sum(const T1 &t1, const T2 &t2)->decltype(t1+t2) // 指定返回类型
{
return t1 + t2;
}template<typename T1, typename T2>
auto mul(const T1 &t1, const T2 &t2)->decltype(t1*t2) // 指定返回类型
{
return t1 * t2;
}void mytest()
{
auto a = ;
auto b = 4L;
auto pi = 3.14f; auto c = mul(sum(a, b), pi);
std::cout << c << std::endl; // 21.98 return;
}int main()
{
mytest(); system("pause");
return ;
}








