我在C++中实现函数式的东西。目前,我正在寻找一种继续传递文件的方式来枚举文件。使用std :: wcout的C++中的高阶函数失败,出现错误C2248
我有一些代码,看起来像这样:
namespace directory
{
void find_files(
std::wstring &path,
std::function<void (std::wstring)> process)
{
boost::filesystem::directory_iterator begin(path);
boost::filesystem::directory_iterator end;
std::for_each(begin, end, process);
}
}
然后我打电话这样说:
directory::find_files(source_root, display_file_details(std::wcout));
...其中display_file_details
这样定义:
std::function<void (std::wstring)>
display_file_details(std::wostream out)
{
return [&out] (std::wstring path) { out << path << std::endl; };
}
该计划是通过延续到find_files
,但能够通过COM向它提出了功能。
但我得到的错误:
error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' :
cannot access private member declared in
class 'std::basic_ios<_Elem,_Traits>'
我在做什么错?我为此尝试疯了吗?
注:我的功能术语(高阶,延续等)可能是错误的。随时纠正我。
您无法通过值传递wostream。仅供参考。 'std :: wostream&out' –
为什么'display_file_details'是一个生成器而不是实际的函数? –
因为我在玩耍,这就是我在功能风格的C#或F#中所做的。如果我在考虑C++ 03,我想可以使用'bind'。 –