jeudi 26 janvier 2017

"cannot convert argument 1 from 'Node

I am writing program with templates in C++, but I can't figure out why it's not compiling.

I have class Node:

template<typename T>
class Node {
friend class Tree<T>;

public:
using nodePtr = std::shared_ptr<Node<T>>;
Node(T value):
    nodeValue(value),
    leftSon(Node()),
    rightSon(Node()),
    isEmpty(false) {
}

Node(T value, nodePtr left, nodePtr right):
    nodeValue(value),
    leftSon(left),
    rightSon(right),
    isEmpty(false) {
}

Node():
    nodeValue(T()),
    leftSon(nullptr),
    rightSon(nullptr),
    isEmpty(true) {
}

Node(nodePtr root):
    nodeValue(root->nodeValue),
    leftSon(root->leftSon),
    rightSon(root->rightSon),
    isEmpty(root->isEmpty) {
}

Node(const nodePtr& copied):
    nodeValue(copied.nodeValue),
    leftSon(copied.leftSon),
    rightSon(copied.rightSon),
    isEmpty(copied.isEmpty) {
}

private:
T nodeValue;
nodePtr leftSon;
nodePtr rightSon;
bool isEmpty;
};

and Tree:

template<typename T>
class Tree {
using nodePtr = std::shared_ptr<Node<T>>;

nodePtr root;

public:
static nodePtr createEmptyNode() {
    return std::make_shared<Node<T>>();
}

static nodePtr createValueNode(T value) {
    return std::make_shared<Node<T>>(value);
}

static nodePtr createValueNode(T value, nodePtr left, nodePtr right) {
    return std::make_shared<Node<T>>(value, left, right);
}
};

When I'm using

Tree<int>::createValueNode(7);

in main function, Visual Studio compiler ends with error:

C2664   
'std::shared_ptr<Node<T>>::shared_ptr(std::shared_ptr<Node<T>> &&) noexcept':
 cannot convert argument 1 from 'Node<T>' to 'std::nullptr_t'

Aucun commentaire:

Enregistrer un commentaire