typeinfo

Can type_info pointers be used to distingush types in C++?

好久不见. 提交于 2020-01-15 23:13:24
问题 I have a set of polymorphic C++ classes and they are all instantiated by the same module (Windows DLL). Now having two pointers to such classes and having called typeid : SomeCommonBase* first = ...; //valid pointer SomeCommonBase* second = ...; //valid pointer const type_info& firstInfo = typeid( first ); const type_info& secondInfo = typeid( second ); can I compare retrieved type_info addresses if( &firstInfo == &secondInfo ) { //objects are of the same class } else { //objects are of

C++: type_info to distinguish types

醉酒当歌 提交于 2020-01-11 16:35:28
问题 I know that compilers have much freedom in implementing std::type_info functions' behavior. I'm thinking about using it to compare object types, so I'd like to be sure that: std::type_info::name must return two different strings for two different types. std::type_info::before must say that Type1 is before Type2 exclusive-or Type2 is before Type1 . // like this: typeid(T1).before( typeid(T2) ) != typeid(T2).before( typeid(T1) ) Two different specialization of the same template class are

C# ITypeInfo.GetContainingTypeLib fails when passed live instance of VBA Class

*爱你&永不变心* 提交于 2019-12-23 07:06:20
问题 So I have experimented on calling ITypeInfo on a VBA Class instance and whilst it looks promising I wanted to see if I could get a reference to its containing project, an analogue to a type library. I thought ITypeInfo.GetContainingTypeLib might be useful but it throws an exception indicating VBA won't co-operate. Anyone got any ideas about how VBA maybe doing things differently from the standard COM specification? The C# Class library code is here. Register for COM interop and set COMVisible

C++ what can make type_info::hash_code differs for two (supposedly) same objects

纵饮孤独 提交于 2019-12-22 14:42:10
问题 After trying to debug an unsuccessful dynamic downcasting, I eventually found that the reason probably is: type_info::hash_code for the type it is casted to is not the same depending where in the code it is called. type_info::name stays exactly the same though. Unfortunately I'm unable to reproduce the behavior in a minimal example since it appears in a quite entangled context. Therefore I'm essentially looking for clues of what can be the cause of such behavior, and consequently what

C++ template name pretty print

三世轮回 提交于 2019-12-21 12:08:39
问题 I have need to print indented template names for debugging purposes. For example, instead of single-line, I would like to indent name like this: boost::phoenix::actor< boost::phoenix::composite< boost::phoenix::less_eval, boost::fusion::vector< boost::phoenix::argument<0>, boost::phoenix::argument<1>, I started writing my own but is getting to be complicated. Is there an existing solution? if there is not one, can you help me to finish up my implementation? I will post it if so. Thanks this

Strange output of std::typeid::name()

China☆狼群 提交于 2019-12-18 12:31:15
问题 I used typeid to get the type names of the std::vector::size_type and a zero sized class A with the following code (cppreference): #include<iostream> #include <vector> #include <typeinfo> using namespace std; class A {}; int main() { vector<int> v(10); vector<int>::size_type s = v.size(); A a; cout << typeid(s).name() << endl; cout << typeid(a).name() << endl; }; And I got this as output: m 1A I guess that "1" before "A" is a result of the Empty Base Class Optimization, but what does "m"

How to determine actual object type at runtime in C++;

不羁的心 提交于 2019-12-18 12:18:07
问题 Lets say we have a class hierarchy. At the bottom we have Base and at the top Derived. How to determine object class even if it is converted to base class pointer. Base* b = new Derived(): typeid(b).name(); // i want this to tell me that this is actually derived not base object is there any way other than manual implementation of string field or such and virtual get function? PS: I talking about compiler-independent solution 回答1: make sure the base class has at least one virtual method,

How to remediate Microsoft typeinfo.name() memory leaks?

不想你离开。 提交于 2019-12-13 05:44:48
问题 Microsoft has a decades old bug when using its leak check gear in debug builds. The leak is reported from the allocation made by the runtime library when using C++ type information, like typeinfo.name() . Also see Memory leaks reported by debug CRT inside typeinfo.name() on Microsoft Connect. We've been getting error reports and user list discussions because of the leaks for about the same amount of time. The Microsoft bug could also mask real leaks from user programs. The latter point is

boost::asio triggers a sigsegv in std::type_info::operator==

匆匆过客 提交于 2019-12-13 00:29:41
问题 So, I've got an application that uses boost::asio. Due to complexity of the project, I cannot share it's source code, sadly :( The application uses boost's asio lib to create some webservices. When attempting to use it, however, there's a sigsegv in std::type_info::operator==, which, as I'm aware, should rather work. (gdb) backtrace #0 0x0000000000457b79 in std::type_info::operator== ( this=0x7ffff6dadf61 <typeinfo for boost::asio::detail::typeid_wrapper<boost::asio::deadline_timer_service