User loginNavigation |
Containers and InheritanceI had a request to implement something similar to the following: If B inherits from A, then B can be passed to a function which takes an A as a parameter just like in any language with inheritance. Make it so that a function taking a list of B can be passed to a function accepting a list of A without conversion beforehand. (And no one cares if it's slow; externally it should require no conversions.) My reasoning against doing this was that this was that it is really equivalent to saying that a list of B inherits from list of A. And if I add a new type of container (mycontainer) which inherits from list, then a mycontainer of B would inherit from all of a mycontainer of A and list of B and a list of A, and that get's really messy. Not a great argument in this particular case as there's no intention to ever support a mycontainer that inherits from list. It got me thinking though, no major languages I know of support this. I can kind of see why for low-level languages like C++ when I think of how object orientation is implemented and speed requirements. However, there must be some deeper theoretical reasoning behind why it's not found in higher level languages than it's just messy. Is it found in languages I don't know, or research languages? If not, why not? Does this type of language feature have a name? The feature request has died, but it's got me curious. By bfraser at 2010-07-23 20:55 | LtU Forum | previous forum topic | next forum topic | other blogs | 5863 reads
|
Browse archives
Active forum topics |
Recent comments
22 weeks 6 days ago
22 weeks 6 days ago
22 weeks 6 days ago
45 weeks 19 hours ago
49 weeks 2 days ago
50 weeks 6 days ago
50 weeks 6 days ago
1 year 1 week ago
1 year 6 weeks ago
1 year 6 weeks ago