please consider the following example:
template <int N, int M>
class MyClass {
private:
void myFunc(void);
public:
void callMe(void);
};
I need to declare a generic pointer to objects of this class. The compiler reject the following statement. What am I doing wrong? Thanks for help.
extern template<int N, int M> MyClass<N, M> *obj;
Why I'm doing this? I need to write a function that is able work with a generic instance of objects from this class, please see the example:
inline template <int N, int M> void MyClass<N,M>::MyFunc(void) { obj = this; };
This is the behaviour I want, if possible. Notice that it works perfectly with NON TEMPLATE types.
void ThisIsAnotherFunction(void) {
obj->callMe();
}
Your different template classes will have nothing in common. What you can do is have your templated classes share a common base class, something like this:
If you want a pointer to a specific concrete type, you have no choice but to provide values for N and M in your declaration.