Hi,
I've a class Handler which contains a STL list
std::list<Abstract*> mAbstract;
which is storing elements of the abstract class Abstract.
Further this class has a getElement function to
return a specific element of the list.
The abstract class Abstract has some virtual pure function
which are used with all concrete classes derived from it.
One of the concrete classes derived from Abstract, let's
call it Concrete_A, has some public functions of specific purpose
and therefore not defined in the abstract class but just in
Concrete_A. Let's assume that one function is
double getTime();
In the future there should be some more concrete classes which
are used for other purposes. To have a "generic model" they
should be derived from class Abstract and added to the STL list
of the handler and finally be accessed by the Handler.
Now let's assume that I have another class Class_A which has a pointer
to the Handler class. Now, my idea is to retrieve the element from the
STL list using the handler and that call the function getTime:
Class_A *object = new Class_A;
double t = object->getHandler()->getElement(_ID_)->getTime();
// _ID_ is a specification of the element from list mAbstract
Doing that the compiler issues an error telling me that the function
getTime() is not known in class Objective.
I though it would be possible to use pointers to objects of the class
Abstract in the STL list of the class Handler and thus the compiler would
recognize at run-time that it's an object of class Concrete_A and call the
corresponding function getTime().
Is this approach feasible? If so, what am I doing wrong?
Thank you.
Chris