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
18
votes
4 answers

What is `type_info::before` useful for?

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…
Paul Manta
  • 30,618
  • 31
  • 128
  • 208
17
votes
2 answers

Use std::type_index as value in a map

I am trying to create a std::unordered_map where the value is a std::type_index. The following snippet works: std::unordered_map workingMap; workingMap[typeid(int)] = 1; workingMap[typeid(char)] = 2; But this one doesn't run…
tversteeg
  • 4,717
  • 10
  • 42
  • 77
17
votes
4 answers

Why is std::type_info polymorphic?

Is there a reason why std::type_info is specified to be polymorphic? The destructor is specified to be virtual (and there's a comment to the effect of "so that it's polymorphic" in The Design and Evolution of C++). I can't really see a compelling…
Doug
  • 8,780
  • 2
  • 27
  • 37
17
votes
3 answers

Is there a relation between RTTI and exceptions?

I remember coding on platforms that had both RTTI and exceptions disabled, and on others that had them both enabled. However, I cannot remember coding on a platform that would enable one and disable the other one. Is there any kind of dependency…
qdii
  • 12,505
  • 10
  • 59
  • 116
16
votes
2 answers

Why do I need to #include when using the typeid operator?

The typeid represents a C++ RTTI operator being also a C++ keyword. It returns a std::type_info object that holds (dynamic) type specific information. From what I understood from various sources, one MUST include when using typeid,…
vsoftco
  • 55,410
  • 12
  • 139
  • 252
16
votes
2 answers

Does using __declspec(novtable) on abstract base classes affect RTTI in any way?

Or, are there any other known negative affects of employing __declspec(novtable)? I can't seem to find references to any issues.
oz10
  • 153,307
  • 27
  • 93
  • 128
15
votes
2 answers

Is it possible to get the value of a GUID on an interface using RTTI?

If I have an interface such as: IPluginAPI = interface ['{590DFF0B-CA00-46CC-84B0-3848103D4C5A}'] function add (a : double; b : double) : double; function sub (a : double; b : double) : double; function mult (a : double; b : double) :…
rhody
  • 2,274
  • 2
  • 22
  • 40
15
votes
4 answers

Numeric unique identifier of a class via typeid

The typeid operator in C++ returns an object of class std::type_info which can yield its textual name. However, I'm just interested in getting an unique numeric identifier for any polymorphic class. (unique in the scope of a single program run - not…
Kos
  • 70,399
  • 25
  • 169
  • 233
15
votes
7 answers

What's a good way to serialize Delphi object tree to XML--using RTTI and not custom code?

What's a good way to serialize a Delphi object tree to XML--using RTTI and not custom code? I would have loved to find that this feature is already built into Delphi, but it doesn't seem to be. I've found a few components (posted, below) that seem…
Mattias Andersson
  • 2,331
  • 1
  • 17
  • 27
15
votes
6 answers

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

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…
Adam
  • 151
  • 1
  • 1
  • 3
15
votes
1 answer

Dynamically Invoking a SOAP method by name?

I am using Delphi XE2 to communicate with a fairly large SOAP service. I've successfully imported the wsdl and everything is working just fine. However, I find myself writing a lot of similar code. I would like to have a generic method that calls my…
dahook
  • 280
  • 2
  • 14
14
votes
3 answers

typeid("") != typeid(const char*)

I'm making a C++ library which relies heavily on RTTI (customizable bridge to another language) and is very confused about string literal type. This is a simple test I made to show the problem: std::cout << typeid(const char*).name() << std::endl;…
val - disappointed in SE
  • 1,475
  • 3
  • 16
  • 40
14
votes
1 answer

Which platforms don't use string comparison in type_info op==?

Here is a typical implementation of type_info::operator==: #if _PLATFORM_SUPPORTS_UNIQUE_TYPEINFO bool operator==(const type_info& __rhs) const { return __mangled_name == __rhs.__mangled_name; } #else bool operator==(const…
Abyx
  • 12,345
  • 5
  • 44
  • 76
14
votes
1 answer

How to create an instance of object with RTTI in Delphi 2010?

As we all known, when we call a constructor of a class like this: instance := TSomeClass.Create; The Delphi compiler actually do the following things: Call the static NewInstance method to allocate memory and initialize the memory layout. Call the…
Baoquan Zuo
  • 652
  • 4
  • 15
14
votes
1 answer

Is it possible to use Attributes on Delphi method arguments?

Is this valid code with newer Delphi versions? // handle HTTP request "example.com/products?ProductID=123" procedure TMyRESTfulService.HandleRequest([QueryParam] ProductID: string); In this example, the argument "ProductID" is attributed with…
mjn
  • 36,362
  • 28
  • 176
  • 378
1 2
3
54 55