#include#include class BaseClass { public: virtual ~BaseClass() {} }; class DerivedClass : public BaseClass { public: ~DerivedClass() {} }; int main() { std::shared_ptr ptr = std::make_shared (); if (ptr->getType() == typeid(DerivedClass)) { std::cout << "DerivedClass type" << std::endl; } return 0; }
#includeThis example demonstrates the use of typeid with std::shared_ptr. First, a shared pointer is created pointing to a dynamically allocated integer object. Then, the typeid function is used to get the type information for both the shared pointer itself and the object it points to. The output shows that the type of the shared pointer is 'class std::shared_ptr#include #include int main() { std::shared_ptr ptr = std::make_shared (42); std::cout << typeid(ptr).name() << std::endl; std::cout << typeid(*ptr).name() << std::endl; return 0; }