Lets say I have three classes.
class A{public:string name;};class B : public A{public:int sortval;};class C : public A{public:int sortval;};
I want to be able to sort B and C together
This is impossible to do in an array since arrays must only contain one datatype. My thought was to use a base class pointer.
So I did this:
B bclass;C cclass;A* pointerToA[2];pointerToA[0] = &bclass;pointerToA[1] = &cclass;cout << pointerToA[0]->sortval; //This doesn't work
After a bit of reading I discovered that the base class pointer to an inherited class cannot access members of the inherited class.
So, how else could I implement something like this?
My original idea before this was to use
struct sortstruct{B b;C c;}sortstruct[100];
then did the sorting by filling each sortstruct with only either b OR c;
This felt sloppy to me so...
Help me out :)