Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ambiguous push_back and operator+= overloads #263

Closed
markand opened this issue Jun 9, 2016 · 1 comment
Closed

Ambiguous push_back and operator+= overloads #263

markand opened this issue Jun 9, 2016 · 1 comment
Labels
solution: invalid the issue is not related to the library

Comments

@markand
Copy link

markand commented Jun 9, 2016

Hello,

I'm trying to add a property to an object like in the example from the README gif, I get an error about ambiguous overload with the following code using GCC 5.1:

#include "json.hpp"

using json = nlohmann::json;

int main()
{
    json j = json::object();

    j += { "anotherkey", false };

    return 0;
}

And the error:

main.cpp: In function 'int main()':
main.cpp:9:4: error: ambiguous overload for 'operator+=' (operand types are 'json {aka nlohmann::basic_json<>}' and '<brace-enclosed initializer list>')
  j += { "anotherkey", false };
    ^
In file included from main.cpp:1:0:
json.hpp:4324:15: note: candidate: nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::value_type& nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::operator+=(nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>&&) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::__cxx11::basic_string<char>; BooleanType = bool; NumberIntegerType = long long int; NumberFloatType = double; AllocatorType = std::allocator; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::reference = nlohmann::basic_json<>&; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::value_type = nlohmann::basic_json<>]
     reference operator+=(basic_json&& val)
               ^
json.hpp:4358:15: note: candidate: nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::value_type& nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::operator+=(const nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>&) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::__cxx11::basic_string<char>; BooleanType = bool; NumberIntegerType = long long int; NumberFloatType = double; AllocatorType = std::allocator; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::reference = nlohmann::basic_json<>&; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::value_type = nlohmann::basic_json<>]
     reference operator+=(const basic_json& val)
               ^
json.hpp:4408:15: note: candidate: nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::value_type& nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::operator+=(const typename nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::object_t::value_type&) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::__cxx11::basic_string<char>; BooleanType = bool; NumberIntegerType = long long int; NumberFloatType = double; AllocatorType = std::allocator; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::reference = nlohmann::basic_json<>&; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::value_type = nlohmann::basic_json<>; typename nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>::object_t::value_type = std::pair<const std::__cxx11::basic_string<char>, nlohmann::basic_json<> >]
     reference operator+=(const typename object_t::value_type& val)
               ^

It works if I use j += json{{ "anotherkey", false }}; though

@markand
Copy link
Author

markand commented Jun 9, 2016

I've just realized it has been fixed in master branch but only present in 1.x.

You can delete this issue, next time I'll search also in closed issues :)

@markand markand closed this as completed Jun 9, 2016
@nlohmann nlohmann added the solution: invalid the issue is not related to the library label Jun 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: invalid the issue is not related to the library
Projects
None yet
Development

No branches or pull requests

2 participants