In this pattern http://gameprogrammingpatterns.com/component.html
with the example:
Bjørn contains an instance of inputComponent and calls its method like input_.update(this*); this method then accesses members of bjørn, like bjorn.velocity -= WALK_ACCELERATION;
I didn’t understand how this could work, each object accessing each others members/methods without causing a dependancy loop. So I made a little test program, but I can’t get it to work. I get the error 'member access into incomplete type 'object''.Am I missing something? Or not understanding the pattern?
My basic test:
object.h:
#include "component.h"
class object{
private:
component _component;
public:
const char* getSomething();
void doSomething();
};
object.cpp:#include "object.h"
void object::doSomething(){
_component.accessThis(*this);
}
const char* getSomething(){
return "something";
}
component.h:#include <iostream>
class object;
class component{
public:
void accessThis(object& obj);
};
component.cpp:#include "component.h"
void component::accessThis(object& obj){
std::cout<< "got" << obj.getSomething() << ".\n";
}