【发布时间】:2018-08-01 18:15:09
【问题描述】:
我需要用nullptrs 初始化vector<unique<TNode>>。 this帖子中的方法太复杂了。我的情况很特殊,因为我只需要将其初始化为nullptr。我怎样才能实现它?
我知道我每次都可以使用 for 循环到 push_back 和 nullptr。有没有优雅的方法?
顺便说一句,make_unqiue 在我的编译器上不起作用。
#include <iostream>
#include <memory>
#include <vector>
using namespace std;
struct TNode {
//char ch;
bool isWord;
vector<unique_ptr<TNode> > children;
TNode(): isWord(false), children(26,nullptr) {}
};
int main()
{
TNode rt;
return 0;
}
【问题讨论】:
-
: children(26)怎么样? -
BTW, make_unqiue does not work on my compiler.在这种情况下它不支持 C++14。 -
@DeiDei 也许
make_unique会起作用
标签: c++ stl c++14 unique-ptr