#include <xtd/console>
class id_info :
public object {
public:
int id_number = 0;
explicit id_info(int id_number) : id_number {id_number} {}
};
class person :
public object {
public:
int age = 0;
return memberwise_clone<person>();
}
auto other = memberwise_clone<person>();
other->id_info = new_ptr<::id_info>(this->id_info->id_number);
other->name = new_ptr<string>(*name);
}
};
void display_values(const person p) {
console::write_line(
" name: {0:s}, age: {1:d}", *
p.name,
p.age);
console::write_line(
" value: {0:d}",
p.id_info->id_number);
}
auto main() -> int {
auto p1 = new_uptr<person>();
p1->age = 42;
*p1->name = "Sam";
*p1->id_info = id_info {6565};
auto p2 = p1->shallow_copy();
console::write_line("Original values of p1 and p2:");
console::write_line(" p1 instance values: ");
display_values(*p1);
console::write_line(" p2 instance values:");
display_values(*p2);
p1->age = 32;
*p1->name = "Frank";
p1->id_info->id_number = 7878;
console::write_line("\nValues of p1 and p2 after changes to p1:");
console::write_line(" p1 instance values: ");
display_values(*p1);
console::write_line(" p2 instance values:");
display_values(*p2);
auto p3 = p1->deep_copy();
*p1->name = "George";
p1->age = 39;
p1->id_info->id_number = 8641;
console::write_line("\nValues of p1 and p3 after changes to p1:");
console::write_line(" p1 instance values: ");
display_values(*p1);
console::write_line(" p3 instance values:");
display_values(*p3);
}
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.h:27
std::unique_ptr< type_t > uptr
The xtd::uptr object is a unique pointer.
Definition uptr.h:25
@ other
The operating system is other.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10