rtti

C++ RTTI Viable Examples [closed]

依然范特西╮ 提交于 2020-01-09 04:19:50
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I am familiar with C++ RTTI, and find the concept interesting. Still there exist a lot of more ways to abuse it than to use it

C++ RTTI Viable Examples [closed]

耗尽温柔 提交于 2020-01-09 04:19:10
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I am familiar with C++ RTTI, and find the concept interesting. Still there exist a lot of more ways to abuse it than to use it

Avoid RTTI when dealing with pairs of objects

倖福魔咒の 提交于 2020-01-06 02:27:04
问题 I saw a few questions about avoiding RTTI, but mine seems to be a bit more specific. Here is an example case: struct Base {}; struct A : Base {}; struct B : Base {}; struct C : Base {}; std::vector<Base*> vec; I want to do something on all possible (unordered) pairs of objects in the vector (if the vector has 3 elements, with 0 and 1, 0 and 2, 1 and 2). The pseudo-code for what I want is something like: if e1 is A and e2 is A: behavior1(e1, e2) elif e1 is A and e2 is B: behavior2(e1, e2) elif

Delphi use reflection in a class procedure for the getting dynamic class type

无人久伴 提交于 2020-01-04 03:37:15
问题 I want use reflection on the current class inside a class procedure/function (static method). How can I do without using the "Self" keyword? And without harcode the class name: this procedure should be override in the descendants. class procedure AAA.SetTableAndSequence; var c : TRttiContext; t : TRttiType; begin c := TRttiContext.Create; try t := c.GetType(Self.ClassType); ... finally c.Free; end; end; 回答1: You can use ClassInfo and GetType: class procedure AAA.SetTableAndSequence; var c:

If my code uses RTTI then it will not work on android?

安稳与你 提交于 2020-01-04 02:45:09
问题 I read in Android Native Development Kit Cookbook that: By default, Android provides minimal C++ support. There's no Run-time Type Information (RTTI) and C++ exceptions support, and even the C++ standard library support, is partial. The following is a list of the C++ headers supported by Android NDK by default: cassert, cctype,cerrno, cfloat, climits, cmath, csetjmp, csignal, cstddef, cstdint, cstdio, cstdlib, cstring, ctime, cwchar, new, stl_pair.h, typeinfo, utility It is possible to add

Does typeid(T) get evaluated at run time or compile time?

不想你离开。 提交于 2020-01-03 08:42:08
问题 I cannot find the answer to this seemingly simple question anywhere. Does the following C++ function use RTTI? It certainly doesn't have to, but I was wondering if there is a guarantee that typeid will be determined at compile time. template <typename T> const char *getName() { return typeid(T).name(); // Resolved at compile time? } 回答1: Since typeid is applied to a type rather than an object, there is no runtime type information, so that overhead won't be a problem. On the other hand: as far

Does typeid(T) get evaluated at run time or compile time?

天大地大妈咪最大 提交于 2020-01-03 08:42:02
问题 I cannot find the answer to this seemingly simple question anywhere. Does the following C++ function use RTTI? It certainly doesn't have to, but I was wondering if there is a guarantee that typeid will be determined at compile time. template <typename T> const char *getName() { return typeid(T).name(); // Resolved at compile time? } 回答1: Since typeid is applied to a type rather than an object, there is no runtime type information, so that overhead won't be a problem. On the other hand: as far

How can i create a new instance of a class?

…衆ロ難τιáo~ 提交于 2020-01-03 03:13:08
问题 i have a list of class instances of various kinds. i need to be able to create a new instance of a class without knowing for sure what to create. all the objects involved have the same ancestor. the actual copying of the object's member variables is easy...it's the creation of the new object where i have a problem. admittedly i could do something like this: case MyObjectTypeInstance.MyTypeEnum of obj1: Result:=TObjectType1.Create; obj2: Result:=TObjectType2.Create; obj3: Result:=TObjectType3

How can I detect if a Delphi class has a virtual constructor?

亡梦爱人 提交于 2020-01-02 18:06:28
问题 For example, is there a way to find out that this class has a virtual constructor (at runtime)? TMyClass = class(TObject) MyStrings: TStrings; constructor Create; virtual; end; For example, in this code I would like to test if the class referenced by Clazz has a virtual constructor: procedure Test; var Clazz: TClass; Instance: TObject; begin Clazz := TMyClass; Instance := Clazz.Create; end; Is there a simple solution, for example using RTTI, which works in Delphi 6 to 2009? 回答1: Looking

How can I detect if a Delphi class has a virtual constructor?

淺唱寂寞╮ 提交于 2020-01-02 18:05:39
问题 For example, is there a way to find out that this class has a virtual constructor (at runtime)? TMyClass = class(TObject) MyStrings: TStrings; constructor Create; virtual; end; For example, in this code I would like to test if the class referenced by Clazz has a virtual constructor: procedure Test; var Clazz: TClass; Instance: TObject; begin Clazz := TMyClass; Instance := Clazz.Create; end; Is there a simple solution, for example using RTTI, which works in Delphi 6 to 2009? 回答1: Looking