T
Till Crueger
Hi,
I am trying to write a programm that will automatically determine were to
send the output. I wanted to use proper Polymorphism for this. In the end
I wanted to arrive at some class called options, which should store all
the options and make them available to the other parts of the programm. I
tried something like this:
class Options{
private:
istream input;
ostream output;
public:
Options();
istream getInput();
ostream getOutput();
}
Options::Options(){
input = cin;
output = cout;
//todo: fill input and output with file streams
}
istream Options::getInput(){
return input;
}
ostream Options::getOutput(){
return output;
}
I would like to be able to call something like:
options.getOutput() << "some text";
and see the output appearing at the right place. This however doesn't work
as I'd like it too, since all the necessary operators or constructors are
private.
I tried substituting variables for references and pointers at several
places, but nothing I did solved the problem.
I also thought about returning some other type for which I could overload
the operators << and >> , but I would rather get along without that, since
then I would have to use an if-statement in the class I am returning,
which is basicly only putting the main issue to another point of the
programm.
Thanks for the help once more *gg*
Till
I am trying to write a programm that will automatically determine were to
send the output. I wanted to use proper Polymorphism for this. In the end
I wanted to arrive at some class called options, which should store all
the options and make them available to the other parts of the programm. I
tried something like this:
class Options{
private:
istream input;
ostream output;
public:
Options();
istream getInput();
ostream getOutput();
}
Options::Options(){
input = cin;
output = cout;
//todo: fill input and output with file streams
}
istream Options::getInput(){
return input;
}
ostream Options::getOutput(){
return output;
}
I would like to be able to call something like:
options.getOutput() << "some text";
and see the output appearing at the right place. This however doesn't work
as I'd like it too, since all the necessary operators or constructors are
private.
I tried substituting variables for references and pointers at several
places, but nothing I did solved the problem.
I also thought about returning some other type for which I could overload
the operators << and >> , but I would rather get along without that, since
then I would have to use an if-statement in the class I am returning,
which is basicly only putting the main issue to another point of the
programm.
Thanks for the help once more *gg*
Till