我的问题是指带有类的指针和关键字 this。
class class1 {
public:
bool isitme(class1& temp){
if(this == &temp)
return true;
else return false;
}
};
int main () {
class1 c3;
class1* c2 = &c3;
if(c3.isitme(*c2))
cout << "c3 == c2"; //it is returning that
system("pause");
}
上面的代码是有效的,但我不明白为什么它只在相同的函数中bool isitme(class1& temp)
起作用。if(this == &temp)
isitme()
我的意思是,我们已经在类参数中读取了class1& temp
temp 的内存块,并且应该能够将该内存块与关键字 进行比较this
。为什么只有当我双重获取参考 ( this == &temp
) 时该函数才为真?
谢谢