Issue
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] | ^~~
Solution
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("") };
//^^^
Answered By - 康桓瑋