Chris wrote:
On Feb 15, 10:30 am, smguo2...@gmail.com wrote:
>On Feb 15, 12:23 pm, "Chris" <Thatch...@gmail.comwrote:
>>Suppose I have the following function signature
>>void foo( Bar &myBar);
>>and I want myBar to be an optional parameter, is there a way to do
the logical equivalent of
>>void foo( Bar &myBar = myBar() )
>>when passing by reference? Every method I've tried gives me syntax
errors.
>>Thanks!
how about
void foo( const Bar &myBar = myBar() )
?
I guess the example I gave there should really be
void foo( Bar &myBar = Bar() );
but anyway, I have every intention of modifying that variable,
That is a rather strange design decision. What is it you're intended
to modify if you pass a temporary in? And if it's documented (and thus
known) that 'foo' modifies its argument, what could be the point of
calling it without an argument?
so
const (while it does fix the syntax problem) is not a viable
solution. Am I stuck making a copy of that variable either by passing
by copy or making a local copy in my function?
No, you can have a global object you'd modify the hell out of when the
caller is careless enough not to supply the argument.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask