Shows hows how to use xtd::object class.
#include <xtd/xtd>
class point : public object {
public:
int x, y;
point(int x, int y) : x {x}, y {y} {}
bool equals(const object& obj) const noexcept override {
if (obj.get_type() != get_type()) return false;
auto& other = static_cast<const point&>(obj);
return x == other.x && y == other.y;
}
size_t get_hash_code() const noexcept override {
return x ^ y;
}
string to_string() const noexcept override {
return string::format("({}, {})", x, y);
}
uptr<point> copy() const {
return memberwise_clone<point>();
}
};
auto main() -> int {
auto p1 = point {1, 2};
auto p2 = p1.copy();
auto& p3 = p1;
console::write_line(object::reference_equals(p1, *p2));
console::write_line(object::equals(p1, *p2));
console::write_line(object::reference_equals(p1, p3));
console::write_line("p1's value is: {}", p1.to_string());
}