我有一个带有成员函数的类模板,它具有要使用类模板参数类型的lambda。它不能在lambda内进行编译,而是在lambda之外按预期成功完成。在lambda成员函数内部访问类模板参数类型失败
struct wcout_reporter
{
static void report(const std::wstring& output)
{
std::wcout << output << std::endl;
}
};
template <typename reporter = wcout_reporter>
class agency
{
public:
void report_all()
{
reporter::report(L"dummy"); // Compiles.
std::for_each(reports_.begin(), reports_.end(), [this](const std::wstring& r)
{
reporter::report(r); // Fails to compile.
});
}
private:
std::vector<std::wstring> reports_;
};
int wmain(int /*argc*/, wchar_t* /*argv*/[])
{
agency<>().report_all();
return 0;
}
的编译错误:
error C2653: 'reporter' : is not a class or namespace name
为什么我不能访问成员函数拉姆达内部类模板参数类型?
我需要做什么才能访问成员函数lambda中的类模板参数类型?
编译我在GCC 4.6。什么是您的平台/编译器? –
@Kerrek:Visual C++ 2010. –