J
J. Campbell
Suppose I have an object that is concatinatable (sp) using the '+'
operator (eg string). I have a function(func)that will do some work
to the object and return an int. For several reasons it is desirable
to have the ability to call the function like this:
int myvalue = func(obj1 + obj2);
because of this am I limited to passing by value? If I demand a pass
by reference, must my calling procedure look like this,
AnObj temp = obj1 + obj2;
intmyvalue = func(temp);
rather than concatinating inside the function parentheses? This second
method defeats the purpose of pass-by-reference, since it creates a
new object anyway.
I realize that I could make the function declaration look like
int func(AnObj&, AnObj&);
but this is undesirable since the function really only needs one
AnObj.
Any advice?
Joe
operator (eg string). I have a function(func)that will do some work
to the object and return an int. For several reasons it is desirable
to have the ability to call the function like this:
int myvalue = func(obj1 + obj2);
because of this am I limited to passing by value? If I demand a pass
by reference, must my calling procedure look like this,
AnObj temp = obj1 + obj2;
intmyvalue = func(temp);
rather than concatinating inside the function parentheses? This second
method defeats the purpose of pass-by-reference, since it creates a
new object anyway.
I realize that I could make the function declaration look like
int func(AnObj&, AnObj&);
but this is undesirable since the function really only needs one
AnObj.
Any advice?
Joe