user152508
user152508

Reputation: 3131

Template class with container with pointers to itself

Is the following possible :

template<class  Container>
class TreeNode
{  

 Container mChildren;
}

TreeNode<std::vector<boost::shared_ptr<TreeNode>> myTreeNode;

Upvotes: 0

Views: 419

Answers (1)

DaVinci
DaVinci

Reputation: 1391

Not like you did. TreeNode is not a class but a class template. I am in a hurry now so this might not be the most simple or elegant way, but it is possible:

#include <vector>

using namespace std;

class Container {};

template<class  Container>
class TreeNode
{  
  Container mChildren;
};

class TreeNodeWrapper;

typedef TreeNode<std::vector<TreeNodeWrapper*> > recursiveTreeNode;

class TreeNodeWrapper : public recursiveTreeNode {
};

recursiveTreeNode myTreeNode;

Upvotes: 2

Related Questions