[英]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.