Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I make "use of deleted" function when passing a std::ofstream as parameter? [duplicate]

Tags:

c++

ofstream

I have a member that is std::ofstream fBinaryFile and a

void setFile( std::ofstream& pBinaryFile ) 
{
    fBinaryFile = pBinaryFile;
}

output:

 Data.h:86:16: error: use of deleted function ‘std::basic_ofstream<char>& std::basic_ofstream<char>::operator=(const
 std::basic_ofstream<char>&)’
     fBinaryFile = pBinaryFile;
                 ^

I understood that copy in std::ofstream is not allowed and maybe I'm missing something. Is possible save the content of pBinaryFile in fBinaryfile?

like image 445
user3050386 Avatar asked Jul 28 '15 10:07

user3050386


1 Answers

Because the relevant operator is declared as

ofstream& operator= (const ofstream&) = delete;

which means it is explicitly prohibited so ofstream semantics does to support copying.

Depending on your architecture you can store a pointer/reference or move it.

like image 174
Alexander Balabin Avatar answered Sep 30 '22 13:09

Alexander Balabin