C++11 类型后置语法

时间:2023-03-09 06:59:11
C++11 类型后置语法
#include <iostream>
#include <typeinfo>
#include <type_traits>
using namespace std;
class OuterType{
public:
struct InnerType {int i; }; InnerType GetInner();
InnerType it;
};
//返回类型后置语法,将decltype和auto结果起来完成返回值类型的推导,
auto OuterType::GetInner() -> InnerType{
return it;
} //返回类型后置语法,将decltype和auto结果起来完成返回值类型的推导,
template <typename T, typename U>
auto add(T t, U u) -> decltype(t + u) {
return t + u;
}
int main()
{
return 0;
}