简体   繁体   English

隐式删除的复制构造函数编译错误返回指针的值

[英]Implicitly-deleted copy constructor compile error returning value of a pointer

sorry if this has already been answered but I couldn't find anything with a possible fix to it. 对不起,如果这已经得到解答,但我找不到任何可能的解决方法。

Consider this class 考虑这个课程

     class NPALog{
public:
    NPALog();
    ~NPALog();

    void error(char* message);
    void warning(char* message);
    void log(char* message);

    void setOutput(char* fileName);
    std::ofstream getLogBuffer(){return *m_logOutputFile;};
    std::ofstream getErrorBuffer(){return *m_errorOutputFile;};


private:
    char* m_fileName;
    std::ofstream *m_logOutputFile;
    std::ofstream *m_errorOutputFile;

 };

When I try to compile it I have this error in the getLogBuffer function: 当我尝试编译它时,我在getLogBuffer函数中有这个错误:

call to implicitly-deleted copy constructor of 'std::ofstream' (aka 'basic_ofstream<char>')

I didn't know too much about copy constructors but the only thing I want to do is work with pointers that allow me to define each ofstream easily later and return the buffer itself if the user want to use it. 我对复制构造函数的了解不多,但我唯一想做的就是使用指针,这些指针允许我稍后轻松定义每个流,如果用户想要使用它,则返回缓冲区本身。

Do you know what can be the problem here? 你知道这里有什么问题吗? Any idea on how to do it better? 有关如何做得更好的任何想法?

Thanks a lot in advance. 非常感谢提前。

You're returning std::ofstream by value from getLogBuffer() and getErrorBuffer() which will make a call to the copy ctor which (as the error message suggests) has been deleted. 您将通过getLogBuffer()getErrorBuffer()的值返回std::ofstream ,这将调用复制ctor(如错误消息所示)已被删除。 You should return a reference instead. 您应该返回引用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 移动构造函数(错误:调用隐式删除的拷贝构造函数) - Move constructor (error: call to implicitly-deleted copy constructor) 错误:调用“ Cadena”的隐式删除副本构造函数 - error: call to implicitly-deleted copy constructor of 'Cadena' 调用RandGenerator的隐式删除的复制构造函数 - Call to implicitly-deleted copy constructor of RandGenerator 向量 <unique_ptr<A> &gt;在构造函数中-错误:调用隐式删除的拷贝构造函数 - vector<unique_ptr<A> > in constructor - error: call to implicitly-deleted copy constructor 尝试将参数传递给方法时出现“调用隐式删除的复制构造函数”错误 - “call to implicitly-deleted copy constructor of” error when tried to pass argument to a method 错误:使用auto调用unique_ptr的隐式删除的复制构造函数 - error: call to implicitly-deleted copy constructor of unique_ptr with auto 错误:调用 &#39;std::__1::unique_ptr 的隐式删除复制构造函数<A, std::__1::default_delete<A> &gt;&#39; - error: call to implicitly-deleted copy constructor of 'std::__1::unique_ptr<A, std::__1::default_delete<A> >' 带矢量的unique_ptr:错误:调用XXX的隐式删除副本构造函数 - unique_ptr with vector: error: call to implicitly-deleted copy constructor of XXX 调用隐式删除的默认构造函数 - Call to implicitly-deleted default constructor 调用 LLVM 中隐式删除的复制构造函数(将代码从 windows 移植到 mac) - Call to implicitly-deleted copy constructor in LLVM(Porting code from windows to mac)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM