rtti

Why is 'pure polymorphism' preferable over using RTTI?

女生的网名这么多〃 提交于 2019-11-27 17:13:53
Almost every C++ resource I've seen that discusses this kind of thing tells me that I should prefer polymorphic approaches to using RTTI (run-time type identification). In general, I take this kind of advice seriously, and will try and understand the rationale -- after all, C++ is a mighty beast and hard to understand in its full depth. However, for this particular question, I'm drawing a blank and would like to see what kind of advice the internet can offer. First, let me summarize what I've learned so far, by listing the common reasons that are quoted why RTTI is "considered harmful": Some

delphi xe disable RTTI

落花浮王杯 提交于 2019-11-27 14:46:30
i have use delphi xe recently but exe size is very big because of rtti(i think) howto remove rtti , and can i make my application size as small as delphi 2009 application(490 kb) without comprssion; and what is the use of rtti gabr In short (full story provided by links in the splash's answer): {$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])} Note that as of XE6 and newer, this needs to be in each individual unit for which you want to disable RTTI. Before that (XE5 and below) it could be in the DPR file and would apply to all units in the project. splash Read the Online Help for Delphi .

No RTTI but still virtual methods

情到浓时终转凉″ 提交于 2019-11-27 14:39:33
问题 C++ code can be compiled with run-time type information disabled, which disables dynamic_cast . But, virtual (polymorphic) methods still need to be dispatched based on the run-time type of the target. Doesn't that imply the type information is present anyway, and dynamic_cast should be able to always work? 回答1: Disabling RTTI kills dynamic_cast and typeid but has no impact on virtual functions. Virtual functions are dispatched via the "vtable" of classes which have any virtual functions; if

C++ - downcasting a diamond shape inherited object without RTTI/dynamic_cast

随声附和 提交于 2019-11-27 13:07:02
问题 I'm currently working on integrating a third-party package that uses lots of RTTI stuff on a non-RTTI platform (Android). Basically, I did my own RTTI implementation but I'm stuck on a problem. The issue is that a lot of classes are having the diamond inheritance problem since all the classes derive from the same base class (object).. and so, if I want to downcast from the base class to the derived class, I have to use a dynamic_cast - but RTTI is not available! How do I convert an object

C++ RTTI Viable Examples [closed]

江枫思渺然 提交于 2019-11-27 11:22:21
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 correctly (the RTTI-switch dread comes to mind). As a developer, I found (and used) only two viable uses for it (more exactly, one and a half). Could you share some of the ways RTTI is a viable solution to a problem, with example code/pseudo-code included? Note: The aim is to have a repository of viable examples a junior developer can consult, criticize and learn from. Edit: You'll find below code using C++ RTTI // A has a virtual destructor (i.e. is polymorphic) // B

What can make C++ RTTI undesirable to use?

流过昼夜 提交于 2019-11-27 10:43:25
Looking at the LLVM documentation, they mention that they use "a custom form of RTTI" , and this is the reason they have isa<> , cast<> and dyn_cast<> templated functions. Usually, reading that a library reimplements some basic functionality of a language is a terrible code smell and just invites to run. However, this is LLVM we're talking of: the guys are working on a C++ compiler and a C++ runtime. If they don't know what they're doing, I'm pretty much screwed because I prefer clang to the gcc version that ships with Mac OS. Still, being less experienced than them, I'm left wondering what

Accessing protected event of TWinControl

人盡茶涼 提交于 2019-11-27 09:48:11
imagine, you want to assign your own event procedure: procedure TSuperObject.DoSomething(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin ShowMessage('Yes, I am doing'); end; to any TWinControl on the form. Normally if you have Panel1 (TPanel) on the form, you can do it easy: Panel1.OnMouseDown:=SuperObject1.DoSomething; But if you want to do it universally, how can it be accomplished? You can not access protected members of TWincontrol, so intuitive answer: AnyWinControl.OnMouseDown:=SuperObject1.DoSomething; simply does not work. Can it be done by RTTI? How?

Type equality test w/ decltype(), auto, or RTTI in C++? Does Boost have something for this?

心已入冬 提交于 2019-11-27 08:17:38
问题 I'm writing some code to translate a C++ type to an appropriate type for a SQL DB. I want to identify the type, and then depending on what it is, produce the appropriate SQL code. I'm not sure exactly what can be done in this regard by using RTTI, auto, or decltype. I have some ideas but I'm not sure if they're workable. For instance (I know the following may not be valid C++, I'm just trying to get the idea across): if (decltype(some_var) == int) { do_stuff(); } or if (decltype(some_var) ==

is vs typeof

蓝咒 提交于 2019-11-27 06:14:47
Which of these pieces of code is faster? if (obj is ClassA) {} if (obj.GetType() == typeof(ClassA)) {} Edit: I'm aware that they don't do the same thing. MagicKat This should answer that question, and then some. The second line, if (obj.GetType() == typeof(ClassA)) {} , is faster, for those that don't want to read the article. Does it matter which is faster, if they don't do the same thing? Comparing the performance of statements with different meaning seems like a bad idea. is tells you if the object implements ClassA anywhere in its type heirarchy. GetType() tells you about the most-derived

dynamic_cast from “void *”

情到浓时终转凉″ 提交于 2019-11-27 05:14:04
According to this , void* has no RTTI information, therefore casting from void* is not legal and it make sense. If I remember correctly, dynamic_cast from void* was working on gcc. Can you please clarify the issue. vitaut dynamic_cast works only on polymorphic types, i.e. classes containing virtual functions. In gcc you can dynamic_cast to void* but not from : struct S { virtual ~S() {} }; int main() { S* p = new S(); void* v = dynamic_cast<void*>(p); S* p1 = dynamic_cast<S*>(v); // gives an error } In 5.2.7 - Dynamic cast [expr.dynamic.cast] it says that for dynamic_cast<T>(v) : If T is a