Quote: "Is there a generic type of pointer that I can use to point to different classes?"
Dodgy - basically, you need to know the pointer type when you extract it from your array to be able to use it.
What you probably need is to design a virtual interface type, and the declare concrete types based on that. Then your pointers will be pointers-to-interface types.
class IBase
{
public:
IBase() { };
virtual ~IBase(); // Allow the user to include their own destructor
virtual int Get() const = 0; // Force a Get function to be defined
virtual void Set(int x) = 0; // Force a Set function to be defined
};
class CNormal : public IBase
{
int x;
public:
void Get() const
{ return x; }
void Set(int x_)
{ x = x_; }
};
class CDouble : public IBase
{
int x;
public:
void Get() const
{ return x; }
void Set(int x_)
{ x = x_ * 2; }
};
...
IBase* MyPtr1 = new CNormal;
IBase* MyPtr2 = new CDouble;
MyPtr1->Set(10);
MyPtr2->Set(10);
std::cout << MyPtr1->Get() << '\n';
std::cout << MyPtr2->Get() << '\n';
...
This code will print 10 and 20, proving that each concrete type is different.
Your array code might look something like this:
IBase MyArray[10][10];
MyArray[0][0] = new CNormal;
Naturally, I'd use a smart pointer (probably boosts shared_ptr class) so that I wouldn't get leaks either ...