不需要类构造函数,但编译器错误导致类没有适当的构造函数

时间:2015-07-13 23:11:26

标签: c++ constructor binary-tree default-constructor

我实例化一个二叉树类的实例,其成员都是节点并拥有自己的适当节点构造函数,以及一个在私有成员声明中立即分配的int。我不知道为什么我仍然会遇到这个编译器错误:

continent   number_of_countries
Antarctica  5
Africa  58

这就是我现在在主要做的事情:

error C2512 'bsTREE<std::string>': no appropriate default constructor available

以下是BSTree和bTNode的类声明:

bSTree<string> trees;

提前感谢您提供任何帮助!

1 个答案:

答案 0 :(得分:0)

如果在类定义中定义构造函数(或任何方法),请不要指定范围:

template <class Item>
class bTNode{

public:

/* Avoid this part:
template <class Item>
bTNode<Item>:: */
bTNode(Item data = Item(), bTNode<Item>* parent = NULL, bTNode<Item>* l = NULL, bTNode<Item>* r = NULL) {
    treeData = data;
    parenting = parent;
    lChild = l;
   rChild = r;
}
};