How to overload operator==() for a pointer to the class?

后端 未结 5 835
北海茫月
北海茫月 2020-12-06 18:06

I have a class called AString. It is pretty basic:

class AString
{
public:
    AString(const char *pSetString = NULL);
    ~AString();
    bool          


        
5条回答
  •  太阳男子
    2020-12-06 18:54

    No, there is not.

    To overload operator==, you must provide a user-defined type as one of the operands and a pointer (either AString* or const char*) does not qualify.
    And when comparing two pointers, the compiler has a very adequate built-in operator==, so it will not consider converting one of the arguments to a class type.

提交回复
热议问题