I'm attempting to implement the Factory Pattern. I have a class called "Window" which has a class member function which determines which object is being called and then assigns the particular object pointer. I have written the following code:
class Hamming {
public:
Hamming() { }
Hamming(int theSize) {
// code
}
};
class Window {
public:
Window() { }
Window* createInstanceOf(int theWindow, size_t size) {
Window* w;
w = new Hamming(100);
return w;
}
};
I want to be able to call it from the following:
Window* w;
w->createInstanceOf(val, val2);
I get the following error:
error: assigning to 'Window *' from incompatible type 'Hamming *'
w = new Hamming(100);
The problem is, I don't really want to use inheritance or have to include every class inside of the implementation of this class (if i had a .h and .cpp file) because this requires EVERY class to be compiled, and, if I only need to use one instance "Hamming" then I don't need to include the others.
Any suggestions?