在下面的代码中
struct BinaryNode {
int val;
BinaryNode *leftchild, *rightchild;
};
struct NaryNode {
int val;
std::vector<NaryNode*> children;
};
我可以将第一个结构初始化为
std::unique_ptr<BinaryNode> bnode1(new BinaryNode{4});
但第二个失败了
std::unique_ptr<NaryNode> nnode1(new NaryNode{4});
是什么赋予了 ?
编辑:编译器错误是
tree.cpp: In function ‘int main()’:
tree.cpp:41:68: error: no matching function for call to ‘NaryNode::NaryNode(<brace-enclosed initializer list>)’
tree.cpp:41:68: note: candidates are:
tree.cpp:10:8: note: NaryNode::NaryNode()
tree.cpp:10:8: note: candidate expects 0 arguments, 2 provided
tree.cpp:10:8: note: NaryNode::NaryNode(const NaryNode&)
tree.cpp:10:8: note: candidate expects 1 argument, 2 provided
tree.cpp:10:8: note: NaryNode::NaryNode(NaryNode&&)
tree.cpp:10:8: note: candidate expects 1 argument, 2 provided
版本:
$ g++ --version
g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
构建命令:
$ g++ -std=c++0x tree.cpp