typeinfo

undefined reference to `typeinfo for class' [duplicate]

余生长醉 提交于 2019-12-03 22:49:33
This question already has answers here : Closed 7 years ago . Possible Duplicate: g++ undefined reference to typeinfo Undefined symbols “vtable for …” and “typeinfo for…”? I can't use my class. class Accel { public: virtual void initialize(void); virtual void measure(void); virtual void calibrate(void); virtual const int getFlightData(byte); }; class Accel_ad : public Accel { public: Accel_ad() : Accel(){} void initialize(void) {/*code code code...*/} void measure(void) {/*measure code*/} const int getFlightData(byte axis){/*getting data*/} void calibrate(void) { int findZero[FINDZERO]; int

Why is std::type_info noncopyable? Am I allowed to store it somewhere?

落爺英雄遲暮 提交于 2019-12-03 15:54:06
问题 The std::type_info class is non-copyable. This makes it hard to store it in an object for later use. What should I do? 回答1: There is a much better solution in C++11. A new copyable wrapper called std::type_index. You need to include header "typeindex" to use it. 回答2: You can store a pointer to a constant std::type_info object. 回答3: From MSDN and IBM online documentation: The type_info class describes type information generated within the program by the compiler. Objects of this class

Why is std::type_info noncopyable? Am I allowed to store it somewhere?

依然范特西╮ 提交于 2019-12-03 05:18:36
The std::type_info class is non-copyable. This makes it hard to store it in an object for later use. What should I do? Silicomancer There is a much better solution in C++11. A new copyable wrapper called std::type_index. You need to include header "typeindex" to use it. You can store a pointer to a constant std::type_info object. matejk From MSDN and IBM online documentation : The type_info class describes type information generated within the program by the compiler. Objects of this class effectively store a pointer to a name for the type. The type_info class also stores an encoded value

C++: type_info to distinguish types

£可爱£侵袭症+ 提交于 2019-12-02 19:21:16
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 considered different types. Two different typedef -initions of the same type are the same type. And finally:

What is `type_info::before` useful for?

只谈情不闲聊 提交于 2019-11-30 11:40:03
According to cplusplus.com, the std::type_info::before() function... Returns true if the type precedes the type of rhs in the collation order. The collation order is just an internal order kept by a particular implementation and is not necessarily related to inheritance relations or declaring order. So what is it useful for? Consider you want to put your type_info objects as keys into a map<type_info*, value> . The type_info doesn't have an operator < defined, so you must provide your own comparator. The only thing that is guaranteed to work from the type_info interface is the before()

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

冷暖自知 提交于 2019-11-30 07:18:16
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" stand for and is this normal? I am using the following gcc version: g++ (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3 G

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

僤鯓⒐⒋嵵緔 提交于 2019-11-30 06:41:10
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 make sure the base class has at least one virtual method, include <typeinfo> and use your current code just with an additional dereferencing, typeid(*b).name() . in

What is `type_info::before` useful for?

北城以北 提交于 2019-11-29 17:34:51
问题 According to cplusplus.com, the std::type_info::before() function... Returns true if the type precedes the type of rhs in the collation order. The collation order is just an internal order kept by a particular implementation and is not necessarily related to inheritance relations or declaring order. So what is it useful for? 回答1: Consider you want to put your type_info objects as keys into a map<type_info*, value> . The type_info doesn't have an operator < defined, so you must provide your

gdb: show typeinfo of some data

吃可爱长大的小学妹 提交于 2019-11-29 06:08:03
问题 Basically, I want to get typeid(*this).name() , i.e. the real type of this . I want to get this in GDB (without modifying the source code). I tried print typeid(*this) but it says that typeid is unknown (because I didn't included it there in the source file). 回答1: Use ptype command, like this: (gdb) ptype 42 type = int 回答2: The 'ptype [ARG]' command will print the type. 回答3: This question may be related: vtable in polymorphic class of C++ using gdb: (gdb) help set print object Set printing of

How to know what type is a var?

百般思念 提交于 2019-11-27 02:50:08
问题 TypeInfo(Type) returns the info about the specified type, is there any way to know the typeinfo of a var? var S: string; Instance: IObjectType; Obj: TDBGrid; Info: PTypeInfo; begin Info:= TypeInfo(S); Info:= TypeInfo(Instance); Info:= TypeInfo(Obj); end This code returns: [DCC Error] Unit1.pas(354): E2133 TYPEINFO standard function expects a type identifier I know a non instantiated var is only a pointer address. At compile time, the compiler parses and do the type safety check. At run time,