but it doesn't compile since the compiler wants this operator to be part of class-definition. also moving this into the class (and omitting the 2nd template-parameter) wont help because for a class with 2 different template-parameters it doesn't make sense. what happened to the late syntax-checking? must I make use of preprocessor in this case? must I define a union? is there any compiler that treats this case differently?
I'm trying to make polymorphic containers without the use of pointers. imagine class A to be a wrapper for a polymorphic list, or maybe an element that can be stored in a vector providing all A-classes to become the same size. at least I haven't seen any such thing anywhere, so I thought I should write one. using pointers to polymorphic class is difficult to debug, often the context of the actual container storing the data is required to understand the program's state. if data is stored and accessed through the container directly (alike to access through iterators), then the program tends to drag around the container's address without much overhead. additionally such a data-storing class can take over some easy tasks like virtual destructor or checking for null-pointer or the difficulties of copying polymorphic classes. but for all that I need to somehow pass on the info about inheritance from the data-type to the encapsulating class -- at least for the case of just those 2 inheritance-levels.
does anyone know of a way to achieve such polymorph-containers? maybe it's possible to have inheritance in unions? for now my solution is to make a "downcast"-method in the iterator (which practically isn't downcasing but rather doing the very reinterpret_cast I write about above). is it a good idea to add such a conversion-to-pointer operator into the iterator instead of typecasting the wrapper-class directly? at least with typecasting the wrapper-class I could pass that class directly as a parameter even when it isn't in a container, can't do that with iterators!
Well, the typecast does not cast anything here but is giving
a permission read/write at a void* memory holder of the member.
It is primarily for system library functions otherwise you will
have to memorize by yourself its storage specifiers.
To achive a polymorfique state of the container there is
a set of functions dealing with the universalaties.