对不起,如果这已经得到解答,但我找不到任何可能的解决方法.
考虑这个课程
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;
};
Run Code Online (Sandbox Code Playgroud)
当我尝试编译它时,我在getLogBuffer函数中有这个错误:
call to implicitly-deleted copy constructor of 'std::ofstream' (aka 'basic_ofstream<char>')
Run Code Online (Sandbox Code Playgroud)
我对复制构造函数的了解不多,但我唯一想做的就是使用指针,这些指针允许我稍后轻松定义每个流,如果用户想要使用它,则返回缓冲区本身.
你知道这里有什么问题吗?有关如何做得更好的任何想法?
非常感谢提前.
你返回std::ofstream的值,从getLogBuffer()和getErrorBuffer()这将使到(因为错误信息显示)已被删除,拷贝构造函数的调用.您应该返回引用.
| 归档时间: |
|
| 查看次数: |
9412 次 |
| 最近记录: |