/*
* c++11关键字
* decltype
* 小鱼号的代码日志
*/
#include <QCoreApplication>
#include <iostream>
using namespace std;
struct st
{
double x;
};
template<typename T,typename U>
auto add(T m,U n) ->decltype(m+n)
{
return m+n;
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
const st* s = new st{0};
auto aa = s->x;
decltype(s->x) y = 0.2; //double
decltype((s->x)) z = y; //double &
auto& cc = y;
cout << aa << " "<< y << " " << z << endl;
y = 0.3;
cout << y << " " << z << endl;
auto g = add(1,0.3);
cout << g << endl;
return a.exec();
}
网友评论