2

I have a small question. Let's say I have

Character char1;
Character char2;

What's the best way to compare if all the member class variables are the same? Can I use memcmp for it? I'm kinda new to this memory stuff, so thanks everyone for help.

4

1 回答 1

5

你不能使用memcmp.

正常的方法是编写自己的相等运算符。

作为非会员,它看起来像

bool operator==(const Character& lhs, const Character& rhs)
{
    return lhs.member1 == rhs.member1 
        && lhs.member2 == rhs.member2 
        && ...
}
于 2018-10-14T14:27:06.933 回答