Код: Выделить всё
class Shape {
bool intersects(const Circle& other) const = 0;
bool intersects(const Line& other) const = 0;
}
class Circle : public Shape {
bool intersects(const Circle& other) const;
bool intersects(const Line& other) const;
}
class Line : public Shape {
bool intersects(const Circle& other) const;
bool intersects(const Line& other) const;
}
bool intersect(Shape* s1, Shape* s2) {
// this does not compile.
return s1->intersects(*s2);
}
Код: Выделить всё
class Shape {
}
class Circle : public Shape {
}
class Line : public Shape {
}
bool intersect(const Circle& s1, const Circle& s2) const;
bool intersect(const Circle& s1, const Line& s2) const;
bool intersect(const Line& s1, const Circle& s2) const;
bool intersect(const Line& s1, const Line& s2) const;
bool intersect(Shape* s1, Shape* s2) {
// this does not compile.
return intersect(*s1, *s2);
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... ion-that-t
Мобильная версия