Lets say I have a template class that encapsulates all video functions. I need the template because there are different color depths for certain modes. Rather than store 3 pointers to 3 types of buffers and screen pointers or creating 3 seperate classes, I use a template.
template <class T> class SVGA
{
T* Buffer;
T* Screen;
T* ScreenPtr;
...
...
};
My problem is this. I also have some classes that need to gain access to the SVGA class so that it can draw lines, points, etc. For instance, let's say that a class called poly2D which encapsulates a 2D polygon object needs access to the SVGA::Line() function in its virtual draw function.
I cannot include a template pointer to the SVGA class inside of the poly class and I really don't want to since this would require you to pass the SVGA object to every class that needed to use it.
Instead I'd like to create a global pointer to the current SVGA object.
SVGA<class T> *SVGAPtr;
Problem is this. The compiler does not know at compile time what class T is. If I try to call SVGA::Line with that pointer the compiler pukes up about 25 errors saying that it cannot cast unsigned char, unsigned short, or unsigned long (depending on the instance of class SVGA) to class T. What I really need is run time type information to determine what class T is so that I can make reference to the SVGA object in the objects that need to use its functions.
Also, I'm not sure that I can derive every object off of template class SVGA since all of its derived classes would not be templates themselves.
Can you use a template class as a base class to derive non-template classes from? Does not sound right to me.
Anyone have any ideas? Salem perhaps?