C++ constructor
by Jerry Mcguire from LinuxQuestions.org on (#55401)
It sounds simple enough when trying to open a file or to test the existence of a file.
Code:{
std::ifstream f("filename");
if (f) {
// file exists
}
}My question is, what is f when "filename" does not exist? To do the same in my own classes, how to write the constructor that returns that "null" object?


Code:{
std::ifstream f("filename");
if (f) {
// file exists
}
}My question is, what is f when "filename" does not exist? To do the same in my own classes, how to write the constructor that returns that "null" object?