If I have the following C++ classes:
class FileIOBase
{
//regular file operations
//
//virtual fstream / ifstream / ofstream getStream(); ???
//
bool open(const std::string &path);
bool isOpen() const;
void close();
...
};
class InputFile : FileIOBase
{
size_t read(...);
ifstream getStream();
};
class OutputFile : FileIOBase
{
size_t write(...);
ofstream getStream();
};
class InputOutputFile : virtual InputFile, virtual OutputFile
{
fstream getStream();
};
The classes just encapsulate standard in, out, in/out file streams and their operations.
Is there any way to make getStream() part of the interface and move it into FileIOBase?
I think you mean to make those return values references instead of values. If that is the case, you can have
getStreamin the base class return aios&, then you can have the specific functions returnfstream&,ifstream&andofstream&s because they are covariant withios&: