以下代码使用 VC++ Nov 2012 CTP 编译。
#include <iostream>
using namespace std;
struct A
{
A(int n)
{
cout << n << endl;
}
};
void f(A)
{}
int main()
{
A {8}; // OK. A::A(8); is called;
cout << typeid(decltype(A {8})).name() << endl; // Output 'struct A'
f(A {8}); // error C2275: 'A' : illegal use of this type as an expression
}
Q1:为什么是 f(A {8});不合法?
Q2:为什么 A {8} 不被视为 A 的实例?
更新:
这个问题似乎是 VC++ Nov 2012 CTP 的一个错误。