[英]Implicitly-deleted copy constructor compile error returning value of a pointer
對不起,如果這已經得到解答,但我找不到任何可能的解決方法。
考慮這個課程
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;
};
當我嘗試編譯它時,我在getLogBuffer函數中有這個錯誤:
call to implicitly-deleted copy constructor of 'std::ofstream' (aka 'basic_ofstream<char>')
我對復制構造函數的了解不多,但我唯一想做的就是使用指針,這些指針允許我稍后輕松定義每個流,如果用戶想要使用它,則返回緩沖區本身。
你知道這里有什么問題嗎? 有關如何做得更好的任何想法?
非常感謝提前。
您將通過getLogBuffer()
和getErrorBuffer()
的值返回std::ofstream
,這將調用復制ctor(如錯誤消息所示)已被刪除。 您應該返回引用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.