Category : rtti

I need to store pointers in such a way that later I’ll be able to restore it’s original type and do some stuff. vector<pair<*void,type_info>> pointers; and later for(auto p : pointers){ switch(p.second) case typeid(sometype): DoStuff((*sometype)p.first); break; //and so on… } When I add pointer I naturally do this SomeType* pointer; pointers.emplace_back((void*)pointer,typeid(SomeType)); And it works fine ..

Read more

I am trying to check the base type of a derived class that is inherited from multiple classes and initially cast from base classes. I used the following approach with the dynamic cast but it seems I missed something. class Base1{ public: virtual ~Base1(){} }; class Base2{ public: virtual ~Base2(){} }; class Derived: public Base1, ..

Read more

Setting aside all the concerns about the necessity of using typeid and dynamic_cast and their questionable effects on code maintenance, is there any information about the performance of these two dynamic type introspection mechanisms? The Wikipedia article on RTTI claims that: The use of typeid, in a non-polymorphic context, is often preferred over dynamic_cast<class_type> in ..

Read more

I want to create a multimap that maps several bitmaps to their specific char. For latin chars there are more bitmaps (because of font size). Also I need to store chinese chars. There are different fonts (called meg5, meg7, _china01). meg-family fonts are used for latin letters and china01 is used for chinese letters. I ..

Read more

I mean to define a function in the base class that is able to print the class of the object calling it, resolving correctly if it is of any derived class. For instance this (expectedly) fails: //====================================================== // demangle is copied from https://stackoverflow.com/a/4541470/2707864 #include <string> #include <typeinfo> std::string demangle(const char* name); template <class T> std::string ..

Read more

Let’s consider the code class Interface { public: virtual ~Interface() {} static void operator delete(void* p, std::size_t s) { std::cout << "Overloaded operator delete for Impl" << std::endl; ::operator delete(p, s); } }; class Implementation : public Interface { public: ~Implementation() { std::cout << "Implementation destructor" << std::endl; } static void operator delete(void* p, std::size_t ..

Read more