Questions tagged [rtti]

RTTI stands for Run-Time Type Information, it is also known as reflection; it allows access to compile-time data at run-time.

RTTI refers to the ability of the system to report on the dynamic type of an object and to provide information about that type at runtime (as opposed to at compile time). When utilized consistently, it can be a powerful tool to ease the work of the programmer in managing resources, or as the basis for writing reflective code. Further explanation can be found on Wikipedia

824 questions
31
votes
10 answers

C++ RTTI Viable Examples

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…
paercebal
  • 81,378
  • 38
  • 130
  • 159
30
votes
4 answers

dynamic_cast with RTTI disabled

I'm curious to know what happens when compiling code with a dynamic cast whith RTTI disabled (either with -fno-rttion GCC or with /GR- on visual studio). Does the compiler "falls back" to static_cast ? Since (at least on VS) it does only issue a…
Louen
  • 3,617
  • 1
  • 29
  • 49
28
votes
1 answer

No RTTI but still virtual methods

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…
Bart van Heukelom
  • 43,244
  • 59
  • 186
  • 301
25
votes
3 answers

Why does `std::make_shared` perform two separate allocations with `-fno-rtti`?

#include struct foo { }; int main() { std::make_shared(); } The asssembly generated by both g++7 and clang++5 with -fno-exceptions -Ofast for the code above: Contains a single call to operator new if -fno-rtti is not passed. Contains…
Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416
25
votes
3 answers

Java isInstance vs instanceOf operator

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 QueryHelper getQueryHelper (Class expectedReturn) { if…
rybit
  • 716
  • 3
  • 17
  • 25
25
votes
3 answers

Why do I get "type has no typeinfo" error with an enum type

I have declared the following enum type in which I want the first member to have the ordinal value of 1 (one) rather than the usual 0 (zero): type TMyEnum = ( meFirstValue = 1, meSecondValue, …
Deltics
  • 22,162
  • 2
  • 42
  • 70
23
votes
6 answers

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

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…
OysterD
  • 6,660
  • 5
  • 34
  • 33
22
votes
5 answers

Removing namespace of type name in C++

In C++, when we use typeid to get type name of an object or class, it will show a decorated(mangled) string. I use cxxabi to demangle it: #include #include namespace MyNamespace { class MyBaseClass { public: const…
masoud
  • 55,379
  • 16
  • 141
  • 208
22
votes
4 answers

RTTI Overhead in C++

What are the memory/performance overheads of enabling RTTI in a C++ program? Can anyone please throw some light between the internal implementation of RTTI mechanism and the relevant overheads? I do understand how to use RTTI through typeid and…
Alok Save
  • 202,538
  • 53
  • 430
  • 533
21
votes
8 answers

Creating a new object from dynamic type info

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…
Daniel
  • 211
  • 1
  • 2
  • 3
20
votes
2 answers

Is there a way to update a field in a record knowing the field name and value

Given a Record: MyRecord = record Company: string; Address: string; NumberOfEmplyees: integer; can you write a function call like function UpdateField(var FieldName: string; FieldValue: variant): bool; so that: UpdateField('Company',…
Charles
  • 315
  • 2
  • 9
19
votes
2 answers

How can I distinguish TDateTime properties from Double properties with RTTI?

Using the RTTI system in Delphi 2010, is there any way to find out if a property is a TDateTime? It's currently treating it as a double whenever I call back asVariant and also if I check the property type. Is this due to the fact it can only see the…
Barry
  • 1,084
  • 1
  • 8
  • 22
19
votes
5 answers

Using RTTI to determine inheritance graph in C++?

What, if any, c++ constructs are there for listing the ancestors of a class at runtime? Basically, I have a class which stores a pointer to any object, including possibly a primitive type (somewhat like boost::any, which I don't want to use because…
trbabb
  • 1,894
  • 18
  • 35
19
votes
2 answers

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

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?
Ivan Prodanov
  • 34,634
  • 78
  • 176
  • 248
19
votes
3 answers

Problems throwing and catching exceptions on OS X with -fno-rtti

The issue is somewhat similar to this question but the accepted answer does not really propose a solution or workaround. In our project, we have a dylib and the main executalble. The dylib is compiled with -fno-rtti, while the executable does use…
Igor Skochinsky
  • 24,629
  • 2
  • 72
  • 109
1
2
3
54 55