jeudi 29 décembre 2016

ostream::operator<< is not working with operator-> in shared_ptr

#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

    }
}

i know that if it works,it works well in other common situation.

this error list

no instance of overloaded function "std::basic_ofstream<_Elem, _Traits>::operator<< [with _Elem=char, _Traits=std::char_traits]" matches the argument list

Aucun commentaire:

Enregistrer un commentaire