#include <iostream>
#include <memory>
{
{
public:
void printName() { std::cout <<
"printName: Foo" << std::endl; }
};
{
public:
virtual void printName() { std::cout <<
"printName: BarBase" << std::endl; }
};
class Bar : public BarBase
{
public:
{
std::cout << "class: Bar" << std::endl;
}
{
std::cout << "specificBarMethod: reached." << std::endl;
}
};
}
{
std::cout << "RTTI Foo (static): " << id_foo->className << std::endl;
Bar::Ptr pBar = std::make_shared<Bar>();
pBar->printName();
pBase->printName();
std::cout <<
"Is Foo? => " << (
IS_DERIVED(pObj,
Foo) ?
"Yes" :
"No")
<< std::endl;
<< std::endl;
std::cout <<
"Is Bar? => " << (
IS_DERIVED(pObj,
Bar) ?
"Yes" :
"No")
<< std::endl;
{
pBar->specificBarMethod();
}
}
{
{
}
}
{
{
for (const auto& cl : allClasses)
{
std::cout << "Known class: " << cl->className << ", children of "
<< (cl->getBaseClass ? cl->getBaseClass()->className
: "(none)")
<< std::endl;
}
}
{
{
pBar->specificBarMethod();
}
}
}
int main(
int argc,
char** argv)
{
try
{
return 0;
}
catch (std::exception& e)
{
std::cout << "Exception: " << e.what() << std::endl;
return -1;
}
}
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::rtti::CObject) is of the give...