   polymorphic classes through templates?
  Okay, say I have a class... and a template class, classes A and 1 (just say that numbers can be used as class names) respectively. Class A is extended by class B, and class 1 has been templated (for my lack of a better word) with class A and class B.Because B extends A, could 1-B- be taken as an argument for a function that's expecting a 1-A-? (yes, I know they aren't the right symbols, but somehow the thinger takes the thinger as... well, an html thinger... thing.)To why I want to do this: Make it easier to use a custom class of vector with 4 elements as a vector class of 3 elements through typedefs.   
  You may wish to show some code for what you're trying to accomplish.   ;  You know... the more I think about it... the more I realize that this isn't that good of an idea... anyways:struct A{ int a;};struct B : public A{ int b;};template<T> class _1{ public:  T ob;  int operator[](int k){return *(k + ((int*)ob));}};something like that. Unfortunately, like I said, the more I think about it the more I think it isn't that good of an idea.EDIT:Regardless, would _1 -B- extend _1 -A-?EDIT: (again...) Thanks jyk...[Edited by - Atash on June 18, 2006 8:00:21 PM];  If you use the < pre >< /pre > or [ source ][ /source ] tags for your excerpt, it should let you use < > template syntax with no trouble, and will also preserve the code formatting. That'll make it easier to read and to deduce what you're wanting to do.   ;Quote:Original post by Atash  int operator[](int k){return *(k + ((int*)ob));}You're making a dangerous assumption here... that objects of type T can be cast into 'pointer to int' (in other words, your implicitly assuming that T will be a pointer... dangerous). It would be safer to enforce that 'ob' is of type T*.Presumably you want a template class such that the template type is a member of a heirarchy and you want the templatisation to be satisfied by any class in the heirarchy.I don't see why you would do things this way, since the normal polymorphic behaviour of C++ classes gives you behaviour adaptable to the position in the heirarchy via the overloading of methods and casting of pointers throughout the heirarchy.Cheers,Timkin;  OOPS!!! I forgot the ampersand + constcast. Anyways...Yeah, I realized I was playing a wierd game in my mind right there... I was just wondering if it were a possibility for exploitation.   