sleep
sleep

Reputation: 4954

Error: initializer must be brace-enclosed

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]       |           ^~~

Upvotes: 2

Views: 1164

Answers (1)

康桓瑋
康桓瑋

Reputation: 43156

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("") };
             //^^^

Upvotes: 7

Related Questions