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

No matching member function for call to 'get_impl' #308

Closed
oysteinmyrmo opened this issue Sep 10, 2016 · 5 comments
Closed

No matching member function for call to 'get_impl' #308

oysteinmyrmo opened this issue Sep 10, 2016 · 5 comments
Labels
solution: invalid the issue is not related to the library

Comments

@oysteinmyrmo
Copy link

oysteinmyrmo commented Sep 10, 2016

I have recently started to use this Json library for my C++ code which will be used as a container for shopping list data on an Android and iOS app. The only thing I use it for (at least so far) is to return an std::string with Json data through objective C++ (iOS) or JNI (Android) for data saving/serialization. This works fine. I am now working to deserialize the Json string to set up the shopping list from saved data. Everything works fine here as well, except this constructor which won't compile:

IngredientCPP(const json& j, int fileFormatVersion);

The error I get when trying to compile the first constructor is

/mypath/shoppinglist/externals/json/json.hpp:2899:16: No matching member function for call to 'get_impl'

The function in question is

template<typename ValueType, typename std::enable_if<
                 not std::is_pointer<ValueType>::value, int>::type = 0>
ValueType get() const
{
    return get_impl(static_cast<ValueType*>(nullptr));
}

I used to have the the above constructor just as

IngredientCPP(const json& j);

which compiles fine, but I need to support multiple format versions in case the saving of the shopping list change in the future (which I know it will). Thus I need to add the integer for versioning. I have trouble seeing what I am doing wrong since I pass const json& j to other constructors where they work just fine, for example this:

ShopGroupSectionManager(const std::vector<ShopGroupCPP>& shopGroups, bool sumIngredients, const json& j)

Any hints that can point me in the right direction? My json.hpp file is downloaded at september 4th, just a week ago. Let me know if additional information is needed.

@oysteinmyrmo
Copy link
Author

I just noticed that having both constructors available makes the code compile, i.e. having

IngredientCPP(const json& j, int fileFormatVersion);
IngredientCPP(const json& j);

compiles, but having just

IngredientCPP(const json& j, int fileFormatVersion);

does not. I have no clue why though.

@nlohmann
Copy link
Owner

Thanks for reporting. It's hard to tell from the distance, but it seems as if the compiler is confused, because json objects can be implicitly converted to a variety of types with the get() method you are quoting.

Could you post the complete error so I may get a clue which types were tried to use?

@oysteinmyrmo
Copy link
Author

Below is what I get from Xcode (non-related stuff removed). It seems it is an implicit conversion from IngredientCPP * to object_t * that fails as it complains that IngredientCPP has no key_type or value_type. I spent some time trying to reproduce the error in a small sample, but I wasn't really able to trigger it.

I also made some changes to my code yesterday and now it compiles fine with only the constructor I want. I cannot see that I did any changes that should affect the json library, but I did change from passing naked pointers of IngredientCPP to std::shared_ptr in a few places. Or rather, I changed from passing naked pointers of IngredientCPP to passing std::shared_ptr of the parent class and doing std::static_pointer_cast later.

Maybe these hints can point you in the right direction? If there is an issue at all - this might have been me not understanding how to use the library properly. Anyway, the issue seems to be gone on my part now. Thanks for getting back so quick.

Output from Xcode compiler:

In file included from /Users/oystein/repositories/myapp/ios/myapp/shoppinglist/src/sections/ShopGroupSection.cpp:1:
In file included from /Users/oystein/repositories/myapp/ios/myapp/shoppinglist/src/sections/../sectionmanagers/../sections/ShopGroupSection.hpp:3:
In file included from /Users/oystein/repositories/myapp/ios/myapp/shoppinglist/src/sections/../sectionmanagers/../sections/Section.hpp:3:
In file included from /Users/oystein/repositories/myapp/ios/myapp/shoppinglist/src/sections/../sectionmanagers/../shoppinglistitems/IngredientCPP.hpp:3:
In file included from /Users/oystein/repositories/myapp/ios/myapp/shoppinglist/src/sections/../sectionmanagers/../shoppinglistitems/ShoppingListItemCPP.hpp:4:
/Users/oystein/repositories/myapp/ios/myapp/shoppinglist/src/sections/../../externals/json/json.hpp:2899:16: error: no matching member function for call to 'get_impl'
        return get_impl(static_cast<ValueType*>(nullptr));
               ^~~~~~~~
/Users/oystein/repositories/myapp/ios/myapp/shoppinglist/src/sections/../../externals/json/json.hpp:3111:16: note: in instantiation of function template specialization 'nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator>::get<IngredientCPP, 0>' requested here
        return get<ValueType>();
               ^
/Users/oystein/repositories/myapp/ios/myapp/shoppinglist/src/sections/ShopGroupSection.cpp:31:51: note: in instantiation of function template specialization 'nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator>::operator IngredientCPP<IngredientCPP, 0>' requested here
                mIngredients.insert(IngredientCPP(item));
                                                  ^
In file included from /Users/oystein/repositories/myapp/ios/myapp/shoppinglist/src/sections/ShopGroupSection.cpp:1:
In file included from /Users/oystein/repositories/myapp/ios/myapp/shoppinglist/src/sections/../sectionmanagers/../sections/ShopGroupSection.hpp:3:
In file included from /Users/oystein/repositories/myapp/ios/myapp/shoppinglist/src/sections/../sectionmanagers/../sections/Section.hpp:3:
In file included from /Users/oystein/repositories/myapp/ios/myapp/shoppinglist/src/sections/../sectionmanagers/../shoppinglistitems/IngredientCPP.hpp:3:
In file included from /Users/oystein/repositories/myapp/ios/myapp/shoppinglist/src/sections/../sectionmanagers/../shoppinglistitems/ShoppingListItemCPP.hpp:4:
/Users/oystein/repositories/myapp/ios/myapp/shoppinglist/src/sections/../../externals/json/json.hpp:2600:14: note: candidate function not viable: no known conversion from 'IngredientCPP *' to 'object_t *' (aka 'map<std::__1::basic_string<char>, nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator>, std::less<basic_string<char> >, allocator<std::pair<const basic_string<char>, basic_json<std::map, std::vector, basic_string<char>, bool, long long, unsigned long long, double, std::allocator> > > > *') for 1st argument
    object_t get_impl(object_t*) const
             ^
/Users/oystein/repositories/myapp/ios/myapp/shoppinglist/src/sections/../../externals/json/json.hpp:2677:13: note: candidate function not viable: no known conversion from 'IngredientCPP *' to 'array_t *' (aka 'vector<nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator>, allocator<nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator> > > *') for 1st argument
    array_t get_impl(array_t*) const
            ^
/Users/oystein/repositories/myapp/ios/myapp/shoppinglist/src/sections/../../externals/json/json.hpp:2734:25: note: candidate function not viable: no known conversion from 'IngredientCPP *' to 'boolean_t *' (aka 'bool *') for 1st argument
    constexpr boolean_t get_impl(boolean_t*) const
                        ^
/Users/oystein/repositories/myapp/ios/myapp/shoppinglist/src/sections/../../externals/json/json.hpp:2664:7: note: candidate template ignored: substitution failure [with T = IngredientCPP]: no type named 'value_type' in 'IngredientCPP'
    T get_impl(T*) const
      ^
/Users/oystein/repositories/myapp/ios/myapp/shoppinglist/src/sections/../../externals/json/json.hpp:2691:18: note: candidate template ignored: disabled by 'enable_if' [with T = IngredientCPP]
                 std::is_convertible<string_t, T>::value, int>::type = 0>
                 ^
/Users/oystein/repositories/myapp/ios/myapp/shoppinglist/src/sections/../../externals/json/json.hpp:2706:18: note: candidate template ignored: disabled by 'enable_if' [with T = IngredientCPP]
                 std::is_arithmetic<T>::value, int>::type = 0>
                 ^
/Users/oystein/repositories/myapp/ios/myapp/shoppinglist/src/sections/../../externals/json/json.hpp:2641:20: note: candidate template ignored: could not match 'vector<type-parameter-0-0, allocator<type-parameter-0-0> >' against 'IngredientCPP'
    std::vector<T> get_impl(std::vector<T>*) const
                   ^
/Users/oystein/repositories/myapp/ios/myapp/shoppinglist/src/sections/../../externals/json/json.hpp:2587:7: note: candidate template ignored: substitution failure [with T = IngredientCPP]: no type named 'key_type' in 'IngredientCPP'
    T get_impl(T*) const
      ^
/Users/oystein/repositories/myapp/ios/myapp/shoppinglist/src/sections/../../externals/json/json.hpp:2619:7: note: candidate template ignored: substitution failure [with T = IngredientCPP]: no type named 'value_type' in 'IngredientCPP'
    T get_impl(T*) const
      ^
1 error generated.


@nlohmann
Copy link
Owner

Thanks for the quick response. Unfortunately, I also cannot figure out the error. As you seem to have fixed it by yourself (though not knowing how ;-)), I think we can close this issue. If you need any support, feel free to ask!

@nlohmann nlohmann added solution: invalid the issue is not related to the library and removed kind: question labels Sep 13, 2016
@nlohmann
Copy link
Owner

(Marked as invalid, because there was no bug in the library)

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