C++の宿題に関する質問があります。私はちょうどこれについて混乱しています。これはC++です。どのように機能するのですか?
以下のコードは私が持っているものです。
私の質問は、=演算子のif文の条件が真である理由です。
#include <cstring>
class abc {
char p[9];
int inc;
public:
abc() { inc = 8; strcpy(p, "10010101"); }
~abc();
abc& operator=(const abc &);
};
abc::~abc() {
}
abc& abc::operator=(const abc &c) {
if(this != &c) { //my question is why this condition is true?
inc = c.inc - 2;
for(int i=0; i<inc; i++) {
p[i] = c.p[i] + 2;
}
}
return *this;
}
int main() {
abc x, y;
x = y;
return 0;
}
私は '二つのオブジェクトxとyがif文の条件を真とするために等しくないのはどういうものなのか理解していますか? – Jack
if条件のアドレスではなく値を比較しているため、アドレスが異なります。 – EdChum
oh yea !!!!!わかった。 – Jack