I want to keep a file as member of following class:
class MyClass
{
public:
MyClass();
~MyClass();
private:
// why this line is OK
std::ifstream fileOK = ifstream("..\\abc.txt");
// why this line is NOT OK
std::ifstream fileNotOK("..\\abc.txt");
};
However if i write that same error line inside any member function then it works:
MyClass::MyClass() {
std::ifstream fileNotOK("..\\abc.txt");
}
also, I notice that, there is No constructor of std::ifstream that has only one parameter like: ifstream (const char* filename)
So How single parameter constructor works and why it cant instantiate member file object like c++ from class declaration.