[Solved] error: ambiguous overload for ‘operator[]’ (operand types are ‘CXmlNode’ and ‘int’)

Phenomena:

After practicing encapsulating xml to rewrite the [ ] operator today, error: ambiguous overload for ‘operator[]’ (operand types are ‘CXmlNode’ and ‘int’) appears when calling.

Function prototype:

class CXmlNode
{<!-- -->
...
CXmlNode & amp; operator[](const char* nodename)
{<!-- -->
....
}
CXmlNode & amp; operator[](uint32_t idx)
{<!-- -->
...
}
...
}

main.cpp:
xmlReader["system"]["logs"][0].Name();

Reason:

Check the information to explain that when calling, the parameters of string and int cannot be recognized.
The reason for the personal test summary is: when the passed parameter is number, it is recognized as int by default, and it will not be automatically converted to an unsigned integer, etc., so an error is reported.

Resolve:

The solution provided on the Internet is to add u behind when the parameter is int when calling. This method can be solved, but it is inconvenient to pay attention to this every time you call, and if the formal parameter type is long, unsigned long, unsigned long long, you should add l, ul, ull accordingly. E.g:

//Take a chestnut
CXmlNode & amp; operator[](unsigned int idx);
xmlReader["system"]["logs"][0u].Name();

CXmlNode & amp; operator[](long idx);
xmlReader["system"]["logs"][0l].Name();

CXmlNode & amp; operator[](unsigned long idx);
xmlReader["system"]["logs"][0ul].Name();

Personal solution: Because my usage scenario will not exceed the maximum value of int (2147483647), directly change the formal parameter to an integer:

CXmlNode & amp; operator[](int idx);

The problem record is only to avoid stepping on a few pits for yourself, and to provide an idea for those who encounter the same problem. If there is something wrong, please comment and point it out, so as to correct it in time and not mislead others.