diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index e728c6ef6..b8df56d45 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -242,7 +242,7 @@ static void GenTable(const Parser &parser, StructDef &struct_def, auto nested_root = parser.structs_.Lookup(nested->constant); assert(nested_root); // Guaranteed to exist by parser. code += " const " + nested_root->name + " *" + field.name; - code += "_nested_root() { return flatbuffers::GetRoot<"; + code += "_nested_root() const { return flatbuffers::GetRoot<"; code += nested_root->name + ">(" + field.name + "()->Data()); }\n"; } // Generate a comparison function for this field if it is a key. diff --git a/tests/monster_test_generated.h b/tests/monster_test_generated.h index f3ff2467d..74bd0d884 100755 --- a/tests/monster_test_generated.h +++ b/tests/monster_test_generated.h @@ -138,7 +138,7 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { const flatbuffers::Vector> *testarrayoftables() const { return GetPointer> *>(26); } const Monster *enemy() const { return GetPointer(28); } const flatbuffers::Vector *testnestedflatbuffer() const { return GetPointer *>(30); } - const Monster *testnestedflatbuffer_nested_root() { return flatbuffers::GetRoot(testnestedflatbuffer()->Data()); } + const Monster *testnestedflatbuffer_nested_root() const { return flatbuffers::GetRoot(testnestedflatbuffer()->Data()); } const Stat *testempty() const { return GetPointer(32); } uint8_t testbool() const { return GetField(34, 0); } bool Verify(flatbuffers::Verifier &verifier) const {