Hi!
I have derived classes `Angle`, `Azimuth`, `Distance`, `Height` from base class `Relation`.
I want to put all of these in a `vector<Relation>` but they have different size, so, I create a `union AnyRelation` and I put all of derived classes inside this union, and the vector become `vector<AnyRelation>`.
When I want to check what type the derived class is, I use `typeid`.
Is there a better approach, or I am going right?
Another try, is to put every derived class in its own vector:
1 2 3
|
vector<Azimuth>
vector<Angle>
vector<Distance>
|
and so on.
and in a `vector<Relation>` I can use references to real objects.
With this approach I can avoid the `typeid` because I can check if pointer of derived class object belongs to a specific `vector`.
And a final question:
Its better to create my own rtti, or to use build-in? (for speed)
My own rtti:
------------
1 2 3 4 5 6 7 8 9 10
|
class A {
A() : rtti(0) {}
int rtti;
int getRTTI() { return rtti; }
bool isB() { return rtti == 1; }
virtual ~A() {}
};
class B : public A {
B() { rtti = 1; }
};
|