Quasar
Moderator

Posts: 4615
Registered: 08-00 |
andrewj said:
I think overloading certain operators, -> for one, just makes for code that's harder to read. Normally if you see "baz->foo()" you'd think the foo() method is being called on a baz object, and this kind of thing subverts that expectation, so that's why I wouldn't use such a construct.
What about when it's what you need to happen?
The problem in particular that I am looking for a solution to in Eternity at the moment is that I want to be able to store qstrings inside MetaTables. In order to do that I need a qstring-containing object derived from MetaObject.
However, I would like to have direct access to all of qstring's 56 methods and not have to jump through an accessor to get to them. I would, if it were not a nightmare, like the MetaObject descendant MetaQString, to behave as if it "is a" qstring.
However, doing that via multiple inheritance, which would be your first instinctual suggestion, would lead to a hideous problem - both MetaObject and qstring share a common base class - they are both ZoneObjects. This would necessitate virtual inheritance, which would, amongst the other problems it creates, make the use of static_cast alongside MetaObject's custom RTTI illegal. The current idiom looks like this, and would be blown to hell:
code:
while((obj = meta->getNextType(obj, METATYPE(MetaString))))
{
// I KNOW it is a MetaString; this is safe.
MetaString *str = static_cast<MetaString *>(obj);
...
}
I wish to avoid multiple inheritance always. I think it leads to bad things in pretty much any situation.
|