[Dune] Assignment operator in DiscreteFunctionDefault
Adrian_Burri
burriad at mathematik.uni-freiburg.de
Fri Jan 28 17:13:47 CET 2005
Hi,
I stumbled on a problem in the DiscreteFunction implementation and would
like to suggest a remedy.
DiscreteFunctionDefault has two methods for assignment:
1.) virtual Vector<...>& operator= (const Vector<...>&), inherited from
Vector<...>
2.) Vector<...>& assign(const Vector<...>&), defined in
DiscreteFunctionDefault
Both are potentially dangerous, because they allow for mixed type
assignments (which might be a feature and not a bug here; however, there
is no means to copy variables defined in subclasses in that case) and
using a static_cast to DiscreteFunctionDefault in the implementation.
Considering this, I suggest to ban operator= altogether (defining one,
but protected) on DiscreteFunctionDefault (and on Vector as well) and
replace assign with a method assignDofs, which does exactly what it has
done until now: it copies the value of the dofs from one function to
another. (Note that this operation makes only sense when both
DiscreteFunction refer to the same DiscreteFunctionSpace. This will be
checked for in the method.)
This solution has the following benefits
1.) Mixed type assignments are possible where it makes sense, with the
guarantee that only dofs are copied
2.) Potentially dangerous and unwanted assignments are banned
3.) If someone wants to come up with an assignment operator on a leaf
class, he can still write one
Please send me comments, suggestions, objections, whatever!
Cheers
Adi
More information about the Dune
mailing list