xtd 0.2.0
Loading...
Searching...
No Matches

◆ get_type()

virtual type_object xtd::object::get_type ( ) const
virtualnoexcept

Gets the type of the current instance.

Returns
The type instance that represents the exact runtime type of the current instance.
Examples
The following code example demonstrates that xtd::object::get_type returns the runtime type of the current instance.
#include <xtd/as>
#include <xtd/console>
using namespace xtd;
class my_base_class : public object {
};
class my_derived_class: public my_base_class {
};
auto main() -> int {
auto my_base = my_base_class {};
auto my_derived = my_derived_class {};
object& o = as<object>(my_derived);
my_base_class& b = as<my_base_class>(my_derived);
console::write_line("my_base: type is {}", my_base.get_type());
console::write_line("my_derived: type is {}", my_derived.get_type());
console::write_line("object o = my_derived: type is {}", o.get_type());
console::write_line("my_base_class b = my_derived: type is {}", b.get_type());
console::write_line("my_base: type is {}", typeof_(my_base));
console::write_line("my_derived: type is {}", typeof_(my_derived));
console::write_line("object o = my_derived: type is {}", typeof_(o));
console::write_line("my_base_class b = my_derived: type is {}", typeof_(b));
}
// This code produces the following output :
//
// my_base: type is my_base_class
// my_derived: type is my_derived_class
// object o = my_derived: type is my_derived_class
// my_base_class b = my_derived: type is my_derived_class
//
// my_base: type is my_base_class
// my_derived: type is my_derived_class
// object o = my_derived: type is my_derived_class
// my_base_class b = my_derived: type is my_derived_class
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
#define typeof_
Used to obtain the type object of a specified type or object.
Definition typeof.h:45
@ b
The B key.
@ o
The O key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Examples
object.cpp.