为什么我要“使用已删除"?函数传递std :: ofstream作为参数时的功能? [英] Why do I make "use of deleted" function when passing a std::ofstream as parameter?

查看:173
本文介绍了为什么我要“使用已删除"?函数传递std :: ofstream作为参数时的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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 中吗?

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?

推荐答案

因为相关的运算符被声明为

Because the relevant operator is declared as

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

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

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.

这篇关于为什么我要“使用已删除"?函数传递std :: ofstream作为参数时的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆