Topic: Virtual operators
Author: "Tom Puverle" <tp225@cam.ac.uk>
Date: Tue, 28 May 2002 17:12:24 GMT Raw View
Does it really make sense to have virtual operators? Wouldn't it be more
sensible to restrict operators to the case when the type of the object is
exactly known? It may make borderline sense to allow UNARY virtual operators
but it seems that binary virtual operators without language support for
multiple dispatch are a bit strange. I really can't come up with an example
where e.g. assignment wouldn't be better handled by handle-body than a
virtual assignment. Very often though one wants to pass params to functions
by reference and those are of course polymorphic. Maybe a "strict" reference
concept that is not a polymorphic but a strict alias for an object?
Just a thought.
Tom
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: James Kanze <kanze@alex.gabi-soft.de>
Date: Wed, 29 May 2002 14:39:41 GMT Raw View
"Tom Puverle" <tp225@cam.ac.uk> writes:
|> Does it really make sense to have virtual operators? Wouldn't it
|> be more sensible to restrict operators to the case when the type
|> of the object is exactly known?
Generally, I agree that overloading and virtuality don't mix well. But
it is a design issue; I don't see any reason why the language should
forbid it.
|> It may make borderline sense to allow UNARY virtual operators but
|> it seems that binary virtual operators without language support
|> for multiple dispatch are a bit strange.
Sort of. But you might want to take a look at what Coplien does.
Generally speaking, if the set of derived classes is closed (which it
sometimes is), binary virtual operators are doable.
|> I really can't come up with an example where e.g. assignment
|> wouldn't be better handled by handle-body than a virtual
|> assignment.
I agree. In the one case that occurs to me, my polymorphic STL
iterator (component Collections/iterator at my site), I basically use
the letter envelop idiom; only the base class supports assignment, and
does so by cloning. (Again, this is something I got from Coplien.)
--=20
James Kanze mailto:kanze@gabi-soft.de
Need real expertise in C++, Java, OO design
I am available, see my CV at www.gabi-soft.de
Ziegelh=FCttenweg 17a, 60598 Frankfurt, Germany Tel. +49(0)69 63198627
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]