I am trying to build a BehaviourTree data structure. The “main” class is “BTNode”, and leaves (actions, commands or conditions) are “BTLeaf”. Because I want a BTLeaf to perform some action on my entities, I made it a template class which takes in an object and a member function pointer.
btnode.h:
#ifndef BTNODE_H
#define BTNODE_H
#include <QLinkedList>
class BTNode
{
public:
BTNode();
BTNode(QLinkedList<BTNode *> &children);
~BTNode();
virtual bool execute() = 0;
protected:
QLinkedList<BTNode*> _children;
};
#endif // BTNODE_H
btleaf.h:
#ifndef BTLEAF_H
#define BTLEAF_H
#include "btnode.h"
template <class T> class BTLeaf : public BTNode
{
public:
BTLeaf(T* object, bool(T::*fpt)(void))
{ _object = object; _fpt=fpt; }
/* Does not work either:
BTLeaf(T* object, bool(T::*fpt)(void))
: BTNode()
{ _object = object; _fpt=fpt; }
*/
virtual bool execute()
{ return (_object->*_fpt)(); }
private:
bool (T::*_fpt)(); //member function pointer
T* _object;
};
#endif // BTLEAF_H
When I try to build the solution (using Qt Creator), I get:
spider.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall BTNode::BTNode(void)" (??0BTNode@@QAE@XZ) referenced in function "public: __thiscall BTLeaf<class Spider>::BTLeaf<class Spider>(class Spider *,bool (__thiscall Spider::*)(void))"
you can see my attempted solution commented out in my code. If I remove the public BTNode part and use my btleaf “manually”, I get the desired result. Any ideas?
Edit:
It might be worth nothing that I create a BTLeaf in my Spider class this way (temporarely, for testing purposes):
BTLeaf<Spider> test(this, &Spider::sayHello);
test.execute();
Presumably that BTNode default (no-argument) constructor you have declared is not defined anywhere (at least, not anywhere that your linker sees).