...
Why would you make the function const if it's going to modify the
object it's called on? And why use the local references at all? It
looks like all you're doing is this:
const Object & Object::dummy(const AType &a)
{
member = a.member();
...
}
I should have said, "it looks like all you're TRYING to do is this:"
-Howard
Not really. It's hard to desribe in a few lines. So I use an example:
I want objects, which refer to other objects of the same type, like the
following by a member function:
Object &
referTo(Object &rhs);
Object oneO, otherO;
oneO.referTo(otherO);
At that point, oneO is a "pointer into" otherO. No problem, as long as
otherO is not const. But if otherO were const, I would like to have oneO
refer to otherO, but oneO should not be able to change otherO. So I make
oneO const, but then I need the const_cast ...
An abuse of const, one might say and he would probably be right. What I
want to implement is a reference, where the referenced object is const (
not modifiable through the reference), not the reference object. Why not
a type of its own for the references? Because all classes are template
classes and there would be plenty of complications, because the
reference shall be used just like the original object and type
conversions for templates together with instantiation ...
Tried to explain my motivation, but must sounds strange and like bad
design, or?
But I have now found a standard conform solution :-).
regards,
Alex