使用std :: wostream参数调用函数指针不起作用

时间:2017-07-12 22:15:09

标签: c++ visual-studio visual-studio-2015 function-pointers iostream

我有一个简化打印到终端的课程:

#include <iostream>
#include <string>

// Functions to append line break(s):
wstring ln(wostream s) { s << endl; return L"\r\n"; }
wstring ln2(wostream s) { s << endl << endl; return L"\r\n\r\n"; }

class Log {
 private:
    wstring prefix, last_log;
 public:
    void operator=(wstring w) {
        system("cls"); // clear terminal
        wcout << prefix << w;
        last_log = w;
    }
    void operator+=(wstring w) {
        system("cls"); // clear terminal
        wcout << prefix << last_log << w;
        last_log += w;
    }

    void operator+=(wstring func(wostream s)) {
        last_log += func(wcout);
        //               ^^^^^
        // Visual Studio reports a syntax error here:
        // "Function ..." can not be referenced (is a deleted function)
    }

    void set_prefix(wstring w) {
        prefix = w;
        system("cls");
        wcout << prefix << last_log;
    }
};

用法:

int main() {
    Log log;
    log = L"Hello";
    log += L" World";
    log += ln; // Append line break!
}

在第23行中,Visual Studio 2015说:(德语)

  

Auf“Funktion”std::basic_ostream<_Elem, _Traits>::basic_ostream(const std::basic_ostream<_Elem, _Traits>::_Myt &) [mit _Elem = wchar_t,_Traits = std :: char_traits]“(deklariert in Zeile 84 von” [...] \ VC \ include \ ostream“)”kann nicht verwiesen werden(isteinegelöschteFunktion)。

翻译:

  

“功能”std::basic_ostream<_Elem, _Traits>::basic_ostream(const std::basic_ostream<_Elem, _Traits>::_Myt &) [mit _Elem = wchar_t,_Traits = std :: char_traits]“(在 [...] \ VC \ include \ ostream“)”无法引用(是已删除的函数)。

导致此错误的原因是什么以及如何解决?

0 个答案:

没有答案