我想知道在這個特殊的情況下,''這個'在'這個'前放了一個星號,''=''重載。在這種情況下做什麼在星號前放置一個星號?
class String
{
private:
int m_length;
char *m_strPtr;
//Utility function
void set_string(const char *string);
public:
String(const char *string); // Default constructor
String(const String &string); // Copy constructor
~String();
int get_length() const { return m_length; };
// Overloaded operators
bool operator!=(const String &rhs) const { return !(*this == rhs); };
bool operator==(const String &rhs) const { return (strcmp(m_strPtr, rhs.m_strPtr) == 0); };
};
爲什麼你會在這種情況下使用'* this'而不是'this'?
'this'是一個指針,'* this'是對象本身的引用 – Brian
所以如果你只是使用'這'你會指的是指針的地址嗎? – anacy
'this'是一個指向對象的指針,所以它保存着對象的地址。 – Brian