Original Post
I'm trying to implement the Observer pattern and run into some problems right away. I'll start with this problem but I'm sure I'll run into more later on which I'll post here too ^^. I'm planning on using this for a simple (but as complete as possible) Pong clone. First I tried implementing it in the most simple way I thought possible: But I receive the following error:
#include <iostream>
#include <list>
using namespace std;
class ISubject;
class IObserver {
public:
virtual void Update(ISubject*);
};
class ISubject {
public:
virtual void Register(IObserver* o) { observerList.push_back(o); }
virtual void Notify(void);
private:
list<IObserver*> observerList;
};
void ISubject::Notify(void) {
for (list<IObserver*>::const_iterator i = observerList.begin();
i != observerList.end(); i++)
{
(*i)->Update(this);
}
}
class Paddle : public ISubject {
public:
void MoveTo(int x, int y) { xPos = x; yPos = y; Notify(); }
private:
int xPos, yPos;
};
class Renderer : public IObserver {
public:
void Update(ISubject*);
};
void Renderer::Update(ISubject* s) {
cout << "Received notification from a subject!" << endl;
};
int main()
{
Paddle myPaddle;
Renderer myRenderer;
myPaddle.Register(&myRenderer);
myPaddle.MoveTo(10, 10);
cin.get();
return 0;
}
Quote:I've never really seen an error like this before and have no idea what it means and what to do with it. Anyone around that does ^^? Thank you in advance.
[Linker error] undefined reference to `vtable for IObserver'