如何使用struct成员初始化std :: vector?

时间:2016-01-23 10:17:02

标签: c++ struct

我有一个结构:

typedef struct Wire {
    std::vector<gate_id_t> _enters_to;
    gate_id_t _out_from;
    bool _is_output;
    void* _data;
    int _sig;
    Wire(bool out)
    :_sig(NO_SIGNAL), _is_output(out),_out_from(NULL),_data(NULL)
    {}
} Wire;

和初始化器宏:

#define INIT_WIRE  {_sig:NO_SIGNAL, _is_output:false, _out_from:NULL, _data:NULL}
  • 我有std::vector<Wire> wires;
  • 当我做wires.resize(new_size,Wire(false));时,它有效。
  • 当我wires.resize(new_size);然后wires[index]=INIT_WIRE;时,我收到错误:error: no match for ‘operator=’ (operand types are ‘__gnu_cxx::__alloc_traits<std::allocator<Wire> >::value_type {aka Wire}’ and ‘<brace-enclosed initializer list>’)
  • 现在,当我初始化const Wire INIT_WIRE = {_sig:NO_SIGNAL, _is_output:false, _out_from:NULL, _data:NULL};时,我收到错误:error: could not convert ‘{2, false, 0l, 0l}’ from ‘<brace-enclosed initializer list>’ to ‘const Wire’

0 个答案:

没有答案