From c9a840e935e574852804205edebd4552a9d111f1 Mon Sep 17 00:00:00 2001 From: Hyungjin Kim Date: Tue, 10 Feb 2015 15:42:38 +0900 Subject: [PATCH] Change nested_root accessor to be const function. The `_nested_root()` is not viable from const object. (We usually get `const Monster *`.) Change-Id: I0d0adcb38dd974318608417ee3094c34fb9c480d --- src/idl_gen_cpp.cpp | 2 +- tests/monster_test_generated.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 {