【发布时间】:2011-01-17 20:22:19
【问题描述】:
#include "stdafx.h"
#include <iostream>
using namespace std;
template<class Type>
struct X
{
void run()const
{//Why on earth this doesn't work?
[&]()
{
Type::alloc();
};
}
void run_1()const
{//if this does
Type::alloc();
}
};
struct T
{
static void alloc()
{}
};
int _tmain(int argc, _TCHAR* argv[])
{
X<T> x;
x.run_1();
return 0;
}
AFAIC lambda 是一个未命名的 fnc,所以如果这是真的,为什么 run 不能编译而 run_1 可以呢?
使用VS2010 sp beta1。
【问题讨论】:
-
我的猜测是,无论你怎么切,那个 lambda 函数都不是 X 的成员,即使它是在
run()中声明的。它与封闭类无关。 -
请给我们VS2010返回的编译错误。
-
我是
error C2653: 'Type' : is not a class or namespace name