fstream 初始化为 class
fstream initialization as a class
在您将其标记为重复之前,我已经阅读了以下内容Q&A。
我有一台名为 ATM 的简单 Class:
ATM.h
class ATM {
public:
ATM(Bank* ownerBank, const char* inputFile);
~ATM();
void performSingleATMAction();
friend void* performSingleATMActionFunc(void* pVoidATM);
private:
Bank* ownerBank;
string inputFile;
fstream fileReader;
Thread mainThread;
static const unsigned int ATM_SLEEP_TIME = 1000*100;
};
我尝试通过初始化列表对其进行初始化:
ATM::ATM(Bank* ownerBank, const char* inputFile) :
ownerBank(ownerBank),
inputFile(inputFile),
fileReader(inputFile,std::ifstream::in), // why copy constructor?
mainThread(performSingleATMActionFunc,this)
{}
行
fileReader(inputFile,std::ifstream::in)
以某种方式调用复制构造函数..这是私有的
有帮助吗?
你可能正在复制 ATM
类型的对象。其中 - 默认情况下 - 复制所有成员。
这需要流的复制构造函数。
Note: having a filestream a member of an ATM class is a design smell to me. ATM machines don't "have-a" file, usually. So, probably you need a (member) function to read "transactions" (just guessing)
在您将其标记为重复之前,我已经阅读了以下内容Q&A。
我有一台名为 ATM 的简单 Class:
ATM.h
class ATM {
public:
ATM(Bank* ownerBank, const char* inputFile);
~ATM();
void performSingleATMAction();
friend void* performSingleATMActionFunc(void* pVoidATM);
private:
Bank* ownerBank;
string inputFile;
fstream fileReader;
Thread mainThread;
static const unsigned int ATM_SLEEP_TIME = 1000*100;
};
我尝试通过初始化列表对其进行初始化:
ATM::ATM(Bank* ownerBank, const char* inputFile) :
ownerBank(ownerBank),
inputFile(inputFile),
fileReader(inputFile,std::ifstream::in), // why copy constructor?
mainThread(performSingleATMActionFunc,this)
{}
行
fileReader(inputFile,std::ifstream::in)
以某种方式调用复制构造函数..这是私有的
有帮助吗?
你可能正在复制 ATM
类型的对象。其中 - 默认情况下 - 复制所有成员。
这需要流的复制构造函数。
Note: having a filestream a member of an ATM class is a design smell to me. ATM machines don't "have-a" file, usually. So, probably you need a (member) function to read "transactions" (just guessing)