From dfe68566e4b90d90635f19f466dc3f4b50a58a4f Mon Sep 17 00:00:00 2001 From: Andrew Gunnerson Date: Mon, 8 Jan 2018 11:26:19 -0500 Subject: [PATCH] Add char * overload for FlatBufferBuilder::CreateString() (#4583) Without this change, the compiler tries to select the following overload when CreateString is passed a `char *`: template Offset CreateString(const T &str) { return CreateString(str.c_str(), str.length()); } which is not valid since char pointers don't have methods. (Fixes #4579) Signed-off-by: Andrew Gunnerson --- include/flatbuffers/flatbuffers.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/flatbuffers/flatbuffers.h b/include/flatbuffers/flatbuffers.h index ef694f749..cdf2c8cf9 100644 --- a/include/flatbuffers/flatbuffers.h +++ b/include/flatbuffers/flatbuffers.h @@ -1001,6 +1001,13 @@ class FlatBufferBuilder { return CreateString(str, strlen(str)); } + /// @brief Store a string in the buffer, which is null-terminated. + /// @param[in] str A char pointer to a C-string to add to the buffer. + /// @return Returns the offset in the buffer where the string starts. + Offset CreateString(char *str) { + return CreateString(str, strlen(str)); + } + /// @brief Store a string in the buffer, which can contain any binary data. /// @param[in] str A const reference to a std::string to store in the buffer. /// @return Returns the offset in the buffer where the string starts.