为什么在传递std :: ofstream作为参数时使用"删除"功能?

use*_*386 4 c++ ofstream

我有一个成员,是std::ofstream fBinaryFile

void setFile( std::ofstream& pBinaryFile ) 
{
    fBinaryFile = pBinaryFile;
}
Run Code Online (Sandbox Code Playgroud)

输出:

 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;
                 ^
Run Code Online (Sandbox Code Playgroud)

我明白std::ofstream不允许复制,也许我错过了一些东西.可以保存的内容pBinaryFilefBinaryfile

Ale*_*bin 9

因为相关运算符被声明为

ofstream& operator= (const ofstream&) = delete;
Run Code Online (Sandbox Code Playgroud)

这意味着它被明确禁止,因此ofstream语义可以支持复制.

根据您的架构,您可以存储指针/引用或移动它.