#include <xtd/console>
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);
}
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());
}
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:42
virtual type_object get_type() const noexcept
Gets the type of the current instance.
std::unique_ptr< type_t > uptr
The xtd::uptr object is a unique pointer.
Definition uptr.hpp:25
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10