私はこのようなクラスを持っています:
class Point
{
public:
int x;
int y;
bool operator==( Point& other )
{
return (x == other.x) && (y = other.y);
}
};
次に、ポイントのベクトルを持つ初歩的な Sprite クラスと、以下に示していない他の多くのメンバー/メソッドがあります。
class Sprite
{
std::vector<Point> points;
};
Point クラスの operator== を使用して、別の Sprite オブジェクトのベクトル内の他の点と衝突する Sprite オブジェクトのベクトル内の任意の Point をどのように見つけますか? 次のようなことを試しましたが、うまくいきません。Size()はポイントのベクトル内のポイントの総数を返し、Points()はポイントのベクトルを返します。
bool Sprite::CollidesWith( Sprite* other )
{
for ( int ixThis = 0; ixThis < Size(); ixThis++ ) {
for ( int ixOther = 0; ixOther < other->Size(); ixOther++ ) {
if ( points->at(ixThis) == other->Points()->at(ixOther) )
return true;
}
}
return false;
}
何か案は?