Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/tutorial/tutorial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int main(int, char*[]) {
printf("a[%d] = %d\n", i, a[i].GetInt());

// Note:
//int x = a[0].GetInt(); // Error: operator[ is ambiguous, as 0 also mean a null pointer of const char* type.
int x = a[0].GetInt(); // this goes to history: "Error: operator[ is ambiguous, as 0 also mean a null pointer of const char* type."
int y = a[SizeType(0)].GetInt(); // Cast to SizeType will work.
int z = a[0u].GetInt(); // This works too.
(void)y;
Expand Down
6 changes: 4 additions & 2 deletions include/rapidjson/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ class GenericValue {
If user is unsure whether a member exists, user should use HasMember() first.
A better approach is to use the now public FindMember().
*/
GenericValue& operator[](const Ch* name) {
template <class T> /* trick here to avoid the ambiguous convertion of (int)0 to (Ch*) and (unsigned int) */
GenericValue& operator[](const T* name) {
if (Member* member = FindMember(name))
return member->value;
else {
Expand All @@ -244,7 +245,8 @@ class GenericValue {
return NullValue;
}
}
const GenericValue& operator[](const Ch* name) const { return const_cast<GenericValue&>(*this)[name]; }
template <class T> /* trick here to avoid the ambiguous convertion of (int)0 to (Ch*) and (unsigned int) */
const GenericValue& operator[](const T* name) const { return const_cast<GenericValue&>(*this)[name]; }

//! Member iterators.
ConstMemberIterator MemberBegin() const { RAPIDJSON_ASSERT(IsObject()); return data_.o.members; }
Expand Down