【发布时间】:2016-06-30 20:54:09
【问题描述】:
刚刚问了一个类似的问题,归结为这个问题。
#include <iostream>
using namespace std;
struct A {
A() : a{1} {};
int a;
};
template <typename Which>
struct WhichType;
int main() {
const A a;
const A& a_ref = a;
const A* a_ptr = &a;
WhichType<decltype(a.a)> which_obj; // template evaluates to int
WhichType<decltype(a_ref.a)> which_ref; // template evaluates to int
WhichType<decltype(a_ptr->a)> which_ptr; // template evaluates to int
return 0;
}
为什么模板没有变成const int 而不是int?
【问题讨论】:
标签: c++ reference constants c++14 decltype