C++ ostream::运算符<&书信电报;未与操作员一起工作->;在共享\u ptr中 #包括 #包括 #包括 类日志 { 私人: 字符串错误日志; 共享的ptr-fs; 公众: Log():errorlog(“”),fs(新的ofstream(“c:\\Log\\Log.txt”),[](ofstream&fs){fs.close();}) { } 无效传输日志(字符串错误日志) { (*fs)
那就别那么做C++ ostream::运算符<&书信电报;未与操作员一起工作->;在共享\u ptr中 #包括 #包括 #包括 类日志 { 私人: 字符串错误日志; 共享的ptr-fs; 公众: Log():errorlog(“”),fs(新的ofstream(“c:\\Log\\Log.txt”),[](ofstream&fs){fs.close();}) { } 无效传输日志(字符串错误日志) { (*fs),c++,c++11,C++,C++11,那就别那么做 重载的操作符那么就不要这样做 重载的运算符 #include<fstream> #include<string> #include<memory> class Log { private: string errorlog; shared_ptr<ofstream> fs; public: Log() :errorlog(""), fs(new ofstream("c:\\Log\\log.txt"), [](o
重载的
操作符那么就不要这样做
重载的运算符
#include<fstream>
#include<string>
#include<memory>
class Log
{
private:
string errorlog;
shared_ptr<ofstream> fs;
public:
Log() :errorlog(""), fs(new ofstream("c:\\Log\\log.txt"), [](ofstream& fs) {fs.close(); })
{
}
void transferLog(string errorlog)
{
(*fs)<<(errorlog) //is working
fs->operator<<(errorlog); //not working
}
}
no instance of overloaded function "std::basic_ofstream<_Elem, _Traits>::operator<< [with _Elem=char, _Traits=std::char_traits<char>]" matches the argument list