Home > front end >  Error: initializer for must be brace-enclosed
Error: initializer for must be brace-enclosed

Time:12-01

What does this error mean and why can't I initialise this struct with a braced initialiser list? Unfortunately the structs are auto-generated.

// Contains no functionality, purely documentative.
struct NativeTable {};

...

struct TableKeyT : public flatbuffers::NativeTable {
  typedef TableKey TableType;
  std::string exp{};
  std::string type{};
  std::string ext{};
};

...

TableKeyT key { std::string(sym), std::string(ex), std::string("") };
[build] ../../../src/io/socket.cpp:102:39: error: initializer for ‘flatbuffers::NativeTable’ must be brace-enclosed
[build]   102 | TableKeyT key { std::string(sym), std::string(ex), std::string("") };
[build]       |           ^~~

CodePudding user response:

Since TableKeyT inherits NativeTable, you also need to initialize the base class, but since it is an empty class, using {} should be fine.

TableKeyT key { {}, std::string(sym), std::string(ex), std::string("") };
             //^^^
  • Related