构造函数系列



我已经编写了这个节点类:

template<class T>
struct Node{
    Node() : content(), col(RED), parent(0), left(0), right(0) {}
    Node(const Node& orig) : content(orig.content), col(orig.col), parent(orig.parent), left(orig.left), right(orig.right) {}
    virtual ~Node() {}
    Node<T>& operator= (const Node<T>& node);
    template <class sT>
    friend std::ostream& operator<<(std::ostream& out,const Node<sT>&node);
    T content;
    Color col;
    Node<T> *parent,*left,*right;
};

现在,我将在一个std::pair中的Node中创建一个Node对象,并编写了以下内容:

Node<Node< pair<int,char> > > n1 (Node<pair<int,char> >( pair<int,char>(45,'a') ));

但是编译器显示了这个错误:

main.cpp:31:84: error: no matching function for call to ‘Node<std::pair<int, char> >::Node(std::pair<int, char>)’

哪种语法才是我想要的?

您缺少一个构造函数:Node(const T& x);

最新更新