Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

cast override suggestion#32

Closed
sergeant-wizard wants to merge 1 commit into
open-source-parsers:masterfrom
sergeant-wizard:master
Closed

cast override suggestion#32
sergeant-wizard wants to merge 1 commit into
open-source-parsers:masterfrom
sergeant-wizard:master

Conversation

@sergeant-wizard

Copy link
Copy Markdown

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
Copy Markdown
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