rtti

activate RTTI in c++

天涯浪子 提交于 2019-11-27 03:03:18
问题 Can anybody tell me how to activate RTTI in c++ when working on unix. I heard that it can be disabled and enabled. on my unix environment,how could i check whether RTTI is enabled or disabled? I am using the aCC compiler on HPUX. 回答1: 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

What are some 'good use' examples of dynamic casting?

泪湿孤枕 提交于 2019-11-27 02:07:34
问题 We often hear/read that one should avoid dynamic casting. I was wondering what would be 'good use' examples of it, according to you? Edit: Yes, I'm aware of that other thread: it is indeed when reading one of the first answers there that I asked my question! 回答1: This recent thread gives an example of where it comes in handy. There is a base Shape class and classes Circle and Rectangle derived from it. In testing for equality, it is obvious that a Circle cannot be equal to a Rectangle and it

Practical usage for Delphi's new RTTI - Attributes,Values

对着背影说爱祢 提交于 2019-11-27 01:13:01
问题 I found a great explanation about the new RTTI in Delphi,but I don't understand one important thing about all I have read - Where can I use that? What is it supposed to replace? 回答1: The extended RTTI works like Reflection in .NET. It gives you access to your internal application structure information. You can access class properties, methods etc.. at runtime, at extent you could not do it before. Some ways of using it: Serialization / Deserialization of classes to XML or other media Mapping

Why should I care about RTTI in Delphi?

守給你的承諾、 提交于 2019-11-27 00:15:27
问题 I've heard a lot about the new/improved RTTI capabilities of Delphi 2010, but I must admit my ignorance...I don't understand it. I know every version of Delphi has supported RTTI...and I know that RTTI (Runtime Type Information) allows me to access type information while my application is running. But what exactly does that mean ? Is Delphi 2010's RTTI support the same thing as reflection in .NET? Could someone please explain why RTTI is useful? Pretend I'm your pointy haired boss and help me

Java isInstance vs instanceOf operator

我是研究僧i 提交于 2019-11-26 23:01:02
问题 The whole generics thing is kinda throwing me for a loop, and more so the RTT. Specificis? Ah well here's the gist: enum QueryHelper { query1, query2; static <T> QueryHelper getQueryHelper (Class<T> expectedReturn) { if (expectedReturn.isInstance (SomeRelatedClass.class)) return query1; else return query2; } } and then I would call it like so: ... QueryHelper helper = QueryHelper.getQueryHelper(SomeRelatedClass.class); ... This is so that I can really flexibly assign the query return type in

Duplicating components at Run-Time

我只是一个虾纸丫 提交于 2019-11-26 21:48:00
问题 Is there a simple way to duplicate all child components under parent component, including their published properties? For example: TPanel TLabel TEdit TListView TSpecialClassX Of course the most important factor, it should duplicate any new component which I drop on the TPanel without modifying the code under normal circumstances. I've heard of the RTTI, but never used it actually. Any ideas? 回答1: have a read of this page Run-Time Type Information In Delphi - Can It Do Anything For You?

When can typeid return different type_info instances for same type?

最后都变了- 提交于 2019-11-26 21:34:41
问题 Andrei Alexandrescu writes in Modern C++ Design: The objects returned by typeid have static storage, so you don't have to worry about lifetime issues. Andrei continues: The standard does not guarantee that each invocation of, say, typeid(int) returns a reference to the same type_info object. Even though the standard does not guarantee this, how is this implemented in common compilers, such as GCC and Visual Studio? Assuming typeid does not leak (and return a new instance every call), is it

Creating a new object from dynamic type info

让人想犯罪 __ 提交于 2019-11-26 19:52:22
问题 In C++, is there any way to query the type of an object and then use that information to dynamically create a new object of the same type? For example, say I have a simple 3 class hierarchy: class Base class Foo : public Base class Bar : public Base Now suppose I give you an object cast as type Base -- which is in reality of type Foo. Is there a way to query the type and use that info to later create new objects of type Foo? 回答1: Clone method There is nothing provided by the language that

Why is 'pure polymorphism' preferable over using RTTI?

帅比萌擦擦* 提交于 2019-11-26 18:55:01
问题 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

What can make C++ RTTI undesirable to use?

偶尔善良 提交于 2019-11-26 17:57:55
问题 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