クラステンプレートパラメータ型を使用するラムダを持つメンバ関数を持つクラステンプレートがあります。それはラムダの内部ではコンパイルに失敗しますが、ラムダの外側では予期どおり成功します。ラムダを持つメンバ関数内のクラステンプレートパラメータ型にアクセスできません
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. –