mercredi 29 mars 2017

error: use of deleted function ‘std::basic_ofstream

std::map<std::string, std::ofstream> Map;
std::string name="name";
std::ofstream ofs(name,std::ios::app);
Map[name] = std::move(ofs);

I run the code above but it failed. I compiled it by g++ 4.9 on Ubuntu12.04 and g++-5 (gcc version 5.4.1 20160904 (Ubuntu 5.4.1-2ubuntu1~12.04) ) using -std=c++11, which induces the same error message below.

error: use of deleted function ‘std::basic_ofstream& std::basic_ofstream::operator=(const std::basic_ofstream&)’ Map[name] = std::move(ofs);

/usr/include/c++/4.9/fstream:602:11: note: ‘std::basic_ofstream& std::basic_ofstream::operator=(const std::basic_ofstream&)’ is implicitly deleted because the default definition would be ill-formed: class basic_ofstream : public basic_ostream<_CharT,_Traits>

Aucun commentaire:

Enregistrer un commentaire