开发者

Implicit conversion between RWCString and const char *

RWCString str = "Y";
str.append("ES");
if("YES" == str)
    cout << "YES == str" << endl;
if(str == "YES")
    cout << "str == YES" << endl;

How does the implicit conversion take place in both cases? Which one is safe to use? RWCString is a string class which ha开发者_运维知识库s a constructor taking const char* and an conversion operator to const char*


It is extremely likely that == is overloaded for comparisons between const char* and RWCString.

Otherwise either str is converted to const char * or the calls are ambiguous:

str == "YES" is ambiguous if there is an external or member operator== comparing two RWCStrings.

"YES" == str is ambiguous if there is an external operator== comparing two RWCStrings.

(assuming that the arguments to the operator== are passed normally -- either through a copy, or a const reference).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜