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

[Bug?] Cannot get int pointer, but int64_t works #468

Closed
koemeet opened this issue Feb 23, 2017 · 4 comments
Closed

[Bug?] Cannot get int pointer, but int64_t works #468

koemeet opened this issue Feb 23, 2017 · 4 comments

Comments

@koemeet
Copy link
Contributor

koemeet commented Feb 23, 2017

Hi! I have been using json["enabled"].get<bool*>() alot and it works perfectly fine. But I cannot get pointers for int and float. For fun I tried other types and I was suprised to see that int64_t did work.

I would expect this to work

int *value = config["range"].get<int*>();
float *health = config["health"].get<float*>();

// this one does work, why?
int64_t *range = config["range"].get<int64_t*>();

Actual results

Severity	Code	Description	Project	File	Line	Suppression State
Error	C2338	incompatible pointer type	Chosseling	c:\users\ik\documents\visual studio 2015\projects\dc\rust\commonsdk\src\json.hpp	3385	
Error	C2664	'const double *nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::get_impl_ptr(const double *) noexcept const': cannot convert argument 1 from 'int *' to 'std::map<StringType,nlohmann::basic_json<std::map,std::vector,StringType,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>,std::less<StringType>,std::allocator<std::pair<const StringType,nlohmann::basic_json<std::map,std::vector,StringType,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>>> *'	Chosseling	c:\users\ik\documents\visual studio 2015\projects\dc\rust\commonsdk\src\json.hpp	3388	

I am not sure if this is a bug or not, if someone could clear this up that would be awesome! 👍

@gregmarr
Copy link
Contributor

It doesn't store int and float, look at the template shown in the error message:

basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>

it stores int64_t, uint64_t, and double.

@koemeet
Copy link
Contributor Author

koemeet commented Feb 23, 2017

@gregmarr I noticed that too indeed, any clue why types like int and float are excluded from that list?

@gregmarr
Copy link
Contributor

It's the types used internally for storing signed integers, unsigned integers, and floating point numbers. There is only one type for each category.

@koemeet
Copy link
Contributor Author

koemeet commented Feb 23, 2017

Ah right! Makes perfect sense now, thanks for clearing it up 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants