使用std :: wcout的C++中的高阶函数失败,错误C2248

Rog*_*mbe 1 c++ functional-programming visual-c++-2010

我正在玩C++中实现功能风格的东西.目前,我正在寻找一种枚举文件的延续传递方式.

我有一些看起来像这样的代码:

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

然后我这样称呼它:

directory::find_files(source_root, display_file_details(std::wcout));
Run Code Online (Sandbox Code Playgroud)

......这里display_file_details的定义如下:

std::function<void (std::wstring)>
    display_file_details(std::wostream out)
{
    return [&out] (std::wstring path) { out << path << std::endl; };
}
Run Code Online (Sandbox Code Playgroud)

计划是通过延续find_files,但能够将组合函数传递给它.

但我得到错误:

error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' :
    cannot access private member declared in
    class 'std::basic_ios<_Elem,_Traits>'
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?尝试这个我是疯了吗?

注意:我的功能术语(高阶,延续等)可能是错误的.随意纠正我.

Ben*_*ley 5

display_file_details,您需要通过引用来获取您的wostream.iostream复制构造函数是私有的.