Skip to content

cast override suggestion #32

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

Closed

Conversation

sergeant-wizard
Copy link

Hi, guys!

Nice project!

I'm just curious, can't we override the type casts so that we don't have to specify Json::Value::as*()?

For example, with your current version, we have to specify the type of the values like:

Json::Value json;
int var1 = json["IntParam"].asInt();
std::string var2 = json["StrParam"].asString();

However, by applying this pull request, we can do something like:

Json::Value json;
int var1 = json["IntParam"];
std::string var2 = json["StrParam"];

without specifying the type, and leave it to the compiler to figure it out from the context.

You may have discussed this prior to transferring to GitHub, but I'd really like to know why you're adapting explicit type specifications without using the features of C++.

Thanks in advance :)

@cdunn2001
Copy link
Contributor

I seem to remember reading something about this on of Scott Meyers' C++ books a long time ago. I highly recommend them.

Anyway, C++ typecast rules are complicated, especially for pointers (e.g. char*). It's much safer to be explicit, though it is a bit more verbose.

@cdunn2001 cdunn2001 closed this Aug 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants