This question already has answers here:
Why copying stringstream is not allowed?
(3个答案)
C++ copy a stream object
(5个答案)
5年前关闭。
我有一个成员,即
输出:
我了解不允许使用
这意味着它被明确禁止,因此
根据您的体系结构,您可以存储指针/引用或移动它。
(3个答案)
C++ copy a stream object
(5个答案)
5年前关闭。
我有一个成员,即
std::ofstream fBinaryFile
和一个void setFile( std::ofstream& pBinaryFile )
{
fBinaryFile = pBinaryFile;
}
输出:
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;
^
我了解不允许使用
std::ofstream
复制,也许我丢失了一些东西。可以将pBinaryFile
的内容保存在fBinaryfile
中吗? 最佳答案
因为相关的运算符被声明为
ofstream& operator= (const ofstream&) = delete;
这意味着它被明确禁止,因此
ofstream
语义确实支持复制。根据您的体系结构,您可以存储指针/引用或移动它。
关于c++ - 当传递std::ofstream作为参数时,为什么要使 “use of deleted”函数? [复制],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31674353/