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
0
votes
1 answer

How to make copy-paste friendly typedef for OuterClass in C++11?

I noticed that the manual designation typedef on OuterClass too costly and sometimes leads to embarrassing errors. So I decided to make a copy-paste friendly typedef on OuterClass. Here's what I got: #include struct A{ typedef A…
Adler
  • 69
  • 7
0
votes
2 answers

Observer pattern with type information (C++)

i'm trying to implement a custom version of an Observer pattern in c++. These are my classes (just interface): class Observer{ public: void observe(std::string behaviour, Observable * observable); void stopObserving(std::string behaviour,…
Luke Givens
  • 829
  • 1
  • 11
  • 15
0
votes
1 answer

run time type information (why this code don't work)

I have a code similar to this (simplified to help present the problem) class a { protected: int m_x; public: a(int x):m_x(x){}; ~a(){}; virtual int GetX()=0; } class b:public a { public: b(int…
mans
  • 17,104
  • 45
  • 172
  • 321
0
votes
2 answers

How to tell old-school `object` and `record` apart?

program Project15; {$APPTYPE CONSOLE} {$R *.res} uses System.Rtti, System.TypInfo; type TRecord = record public AField: integer; constructor Init(test: integer); end; TOldObject = object public AField: integer; …
Johan
  • 74,508
  • 24
  • 191
  • 319
0
votes
1 answer

Which Design Pattern / RTTI

I'm looking for the best way to dispatch objects to the correct "target" object. I have a base command class: Cmd, two sub-classes: BufferCmd and StateCmd. Command "GotoLine" is derived from BufferCmd and "ChangeCmd" is derived from StateCmd. …
Shaun
  • 3,777
  • 4
  • 25
  • 46
0
votes
4 answers

C++ fast dynamic type/subtype check

As the title suggests, I am looking for a fast way of runtime typechecking. To illustrate my problem, imagine you have a class hierarchy like the following: Base / \ A D / \ / \ C B F E \ / …
rootmenu
  • 33
  • 5
0
votes
3 answers

Use of RTTI in C++

What is the use of run time type identification in C++? I know how it is used and what facilities it provides but what was the motivation behind introducing RTTI in C++? Can anyone give a small example where RTTI has to be used?
username_4567
  • 4,737
  • 12
  • 56
  • 92
0
votes
1 answer

How to use RTTI to determine the behavior of code

I have a piece of code to use the RTTI as case selector #include #include #include #include #include using namespace std; typedef complex data; typedef std::vector< data > List; template…
user1285419
  • 2,183
  • 7
  • 48
  • 70
0
votes
2 answers

Practical uses of exploiting RTTI in C++

Having done with 1st Vol. of Thinking in C++ by Bruce Eckel, I have started reading the 2nd Vol. The chapter devoted to RTTI (Run-Time Type Identification) amazes me the most. I have been reading about tyepid, dynamic_cast, etc. But, I have a…
Sankalp
  • 2,796
  • 3
  • 30
  • 43
0
votes
1 answer

Building and evaluating expressions using Delphi RTTI

I am faced with a task of allowing the user to define the expressions using the compiled classes with RTTI enabled. Let me put it in a simple way. TAnimal = class(TPersistent) private fWeight : Double; fHeight : Double; fName :…
Rahul W
  • 833
  • 11
  • 26
0
votes
1 answer

Delphi create subclass running time in property

Hello I have a question is possible I do a loop for create subclass in Delphi? I saw some about RTTI but I can't found how create a class in property in run time exemple thank you Type TclassX = class private public X1 : integer; X2…
0
votes
1 answer

generic recursive function which TRttiField SetValue on Record doesn't work

I have a "parent" class which has a generic function to load a JSON string into the instance's properties called loadVals. I have two children with their own properties, and one of these props is a record. The function sets successfully all the…
Givius
  • 1,008
  • 8
  • 12
0
votes
0 answers

How to set value to a dynamic array using the rtti?

I'm trying this way, however the size remains 0 v := _RttiFld.GetValue(obj); P := v.GetReferenceToRawData; idx := 2; //to test DynArraySetLength(p,v.TypeInfo,1,@idx); Assert(_RttiFld.GetValue(obj).GetArrayLength > 0); My field is a…
drgarcia1986
  • 343
  • 1
  • 5
0
votes
1 answer

C++: Using typeid before heap allocation

class A { protected: int a; public: A(); A(int); virtual void print()=0; virtual ~A(); }; class B: public A { int b; public: B(); B(int,int); //initialize attributes a and b void print(); //print a and…
Cristi
  • 1,195
  • 6
  • 17
  • 24
0
votes
1 answer

specifying an object type at runtime

Possible Duplicate: Is there a way to instantiate objects from a string holding their class name? I've written a Vbo template class to work with vertex buffer objects in opengl. I'm writing for multiple platforms in c++. I'd like to set the…
fishfood
  • 4,092
  • 4
  • 28
  • 35