如何初始化std :: unique_ptr <T>的类成员数组?

时间:2019-12-29 14:33:31

标签: c++ arrays class

我有一个包含import {Component} from '@angular/core'; import str from 'raw-loader!./app.component.htm'; @Component({ selector: 'app-root', template: str, // notice not url just string styleUrls: ['./app.component.css'] }) export class AppComponent { } 成员std::array的类。声明如下:

std::unique_ptr<T>

我尝试了几种初始化此数组的方法。只是这样写一个初始化列表:

class Context
{
public:
    Context();
private:
    std::array<std::unique_ptr<InvokerBoolean>, GLFW_KEY_LAST + 1> _keymap;
}

这会编译,但保留所有指向0xcdcdcdcdcd的指针,这是一个非NULL值,这不好,因为我希望能够编写

Context::Context()
    : keymap()
{}

如果我没有在索引i上明确设置指针,则获取一个if (_keymap[i]) 值。

false

这不能编译,错误是说: _keymap(std::move(std::make_unique<InvokerBoolean>(nullptr))) 构造函数的任何实例都不采用参数类型。

如何初始化数组,以便在创建std::array时所有指针都指向NULL值?

0 个答案:

没有答案