dynamic_cast with RTTI disabled

Reading the standard, in 5.2.7/6 we find that unless the target is an unambiguous base of the source, source must be a polymorphic type. Then in 10.3/1 Virtual functions support dynamic binding and objectoriented programming. A class that declares or inherits a virtual function is called a polymorphic class. In other words the standard doesn’t … Read more

Why use std::type_index instead of std::type_info*

type_index is “a simple wrapper for type_info which can be used as an index type in associative containers (23.4) and in unordered associative containers (23.5)”. If you use type_index instead of type_info*, you will free yourself from having to provide an explicit comparator in your maps. The only cost is that you need to #include … Read more

What’s the difference between public and published class members in Delphi?

The compiler generates RTTI (Run-Time Type Information) metadata for published members, but not for public members (by default). The main effect of this is that the published properties of an object will appear in the Object Inspector at design time. I do not know if you are writing components, but if you do, you probably … Read more

activate RTTI in c++

Are you using g++ or some other compiler? In g++ RTTI is enabled by default IIRC, and you can disable it with -fno-rtti. To test whether it is active or not use dynamic_cast or typeid UPDATE I believe that HPUX’s aCC/aC++ also has RTTI on by default, and I am unaware of a way to … Read more

Extract C++ template parameters

It’s not possible in general to pick arbitrary template parameters. However, the usual way you do it is this: template<int N> struct foo { static const int value = N; }; and for types template<typename T> struct foo { typedef T type; }; You can access it then as foo<39>::value or foo<int>::type. If you have … Read more

Is it safe to use the address of a static local variable within a function template as a type identifier?

Yes, it will be correct to an extent. Template functions are implicitly inline, and static objects in inline functions are shared across all translation units. So, in every translation unit, you will get the address of the same static local variable for the call to type_id<Type>(). You are protected here from ODR violations by the … Read more

std::any without RTTI, how does it work?

TL;DR; std::any holds a pointer to a static member function of a templated class. This function can perform many operations and is specific to a given type since the actual instance of the function depends on the template arguments of the class. The implementation of std::any in libstdc++ is not that complex, you can have … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)