0

I have a 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;

and an initializer macro:

#define INIT_WIRE  {_sig:NO_SIGNAL, _is_output:false, _out_from:NULL, _data:NULL}
  • I have a std::vector<Wire> wires;
  • When I do wires.resize(new_size,Wire(false)); it works.
  • When I do wires.resize(new_size); and then wires[index]=INIT_WIRE; I get the error: error: no match for ‘operator=’ (operand types are ‘__gnu_cxx::__alloc_traits<std::allocator<Wire> >::value_type {aka Wire}’ and ‘<brace-enclosed initializer list>’)
  • now, when I initialize const Wire INIT_WIRE = {_sig:NO_SIGNAL, _is_output:false, _out_from:NULL, _data:NULL}; I get the error: error: could not convert ‘{2, false, 0l, 0l}’ from ‘<brace-enclosed initializer list>’ to ‘const Wire’
Bush
  • 2,433
  • 5
  • 34
  • 57
  • 2
    Why would you use `typedef struct` in C++ (with a `vector` member)? Why macro? Why not to write a proper constructor overload? You might want to check this Q&A: [The Definitive C++ Book Guide and List](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – Ivan Aksamentov - Drop Jan 23 '16 at 10:22
  • I don't see a `_sig` member defined in `Wire`, that could explain a lot. – mostruash Jan 23 '16 at 10:26
  • there is _sig, deleted while copying code to SO by mistake.. – Bush Jan 23 '16 at 10:29
  • This is very much a case of "pick your language". Pick C++ for `vector` and constructors. Pick C99 for `typedef struct`, `void*`, and designated initializer lists. – MSalters Jan 23 '16 at 13:23

0 Answers0