S
shaun roe
I am about to replace a plain function which returns a string with an
object; I am trying to preserve the interface to clients of the
function, while imbuing the function with some internal state.
lets say the function is
string foo(int myInt);
I thought to make an object with constructor f(int myInt) and hide the
default constructor, copy, assignment (anything else?), but provide some
overloaded string conversion operators, with prototypes
foo:perator string ();
foo:perator char * ();
Questions:
1) Does this work?
2) Do I need to provide const versions of the overloaded conversions?
3) Is there a better way, possibly using just operator()?
eventually the client has to use it the same way as a function, like
string myString=f(5);
or
const string myString=f(4);
???
many thanks
shaun
object; I am trying to preserve the interface to clients of the
function, while imbuing the function with some internal state.
lets say the function is
string foo(int myInt);
I thought to make an object with constructor f(int myInt) and hide the
default constructor, copy, assignment (anything else?), but provide some
overloaded string conversion operators, with prototypes
foo:perator string ();
foo:perator char * ();
Questions:
1) Does this work?
2) Do I need to provide const versions of the overloaded conversions?
3) Is there a better way, possibly using just operator()?
eventually the client has to use it the same way as a function, like
string myString=f(5);
or
const string myString=f(4);
???
many thanks
shaun