【发布时间】:2014-01-10 17:24:13
【问题描述】:
我已经创建了这个类:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class XLSCreator
{
private:
ofstream filecontents;
int fileType;
int cellNumber;
int rowsNumber;
public:
XLSCreator(string);
~XLSCreator();
void createType1File(string, string, string);
void createType2File(string, string, string, string, string);
void addNewRow();
void addData(string);
void saveFile();
};
但是当我尝试构建它时,它给了我这个错误:
错误 2 错误 C2248:“std::basic_ofstream<_elem>::basic_ofstream”:无法访问在类“std::basic_ofstream<_elem>”中声明的私有成员
那么有人可以帮我解决这个问题吗?
【问题讨论】:
-
复制什么?代码有什么问题?
-
std::ofstream是不可复制的。据推测,您正在尝试复制您的类,而默认的复制构造函数只是按成员复制文件流。 -
所以我不能使用 std::ofstream 作为成员变量?
-
你可以,我可以很好地编译你的类,但你不能依赖默认行为来复制它。你必须解决这个问题,具体如何取决于你想要什么,真的。