Code:
class Bar;
class Foo
{
public:
Foo() { p_Bar = NULL;}
~Foo() {}
void setBar(Bar *b) { p_Bar = b;}
void doSomething()
{
std::cout<< "Hey I'm Foo and I'm doing something\n";
notifyBar();
}
private:
Bar *p_Bar;
void notifyBar() {if (p_Bar != NULL) p_Bar->update();}
protected:
};
class ControlFoo
{
public:
ControlFoo() {}
~ControlFoo() {}
void setFoo(Foo *f) {m_f = f;}
void controlSomething() {m_f->doSomething();}
private:
Foo *m_f;
protected:
};
class Bar
{
public:
Bar() {}
~Bar() {}
virtual void update() = 0;
void setControlFoo(ControlFoo *cf) {m_cf = cf;}
private:
protected:
ControlFoo *m_cf;
};
class BarBar: Bar
{
public:
BarBar(): Bar() {}
~BarBar() {}
virtual void update();
void doBBSomething();
private:
protected:
};
void
BarBar::update()
{
std::cout << "Hey! we got some update!\n";
}
void
BarBar::doBBSomething()
{
m_cf->controlSomething();
}
The following example gives me the error
t1.hpp: In member function ‘void Foo::notifyBar()’:
t1.hpp:19: error: invalid use of incomplete type ‘struct Bar’
t1.hpp:3: error: forward declaration of ‘struct Bar
Can anyone help me understand this? Is this because Bar is not yet an complete type and the call in notifyBar requires it to be?
Thanks!