rtti

When and why is an std::__non_rtti_object exception generated?

天大地大妈咪最大 提交于 2019-12-10 16:05:34
问题 I'm using Visual Studio and performing a valid dynamic cast. RTTI is enabled. Edit : Updated the code to be more realistic struct base { virtual base* Clone() { base* ptr = new base; CopyValuesTo( ptr ); return ptr; } virtual void CopyValuesTo( base* ptr ) { ... } virtual ~base() { } } struct derived : public base { virtual base* Clone() { derived* ptr = new derived; CopyValuesTo( ptr ); return ptr; } virtual void CopyValuesTo( base* ptr ) { ... } virtual ~derived() { } } void Class1:

What's the lifetime of memory pointed to typeinfo::name()?

 ̄綄美尐妖づ 提交于 2019-12-10 14:15:35
问题 In C++ I can use typeid operator to retrieve the name of any polymorphic class: const char* name = typeid( CMyClass ).name(); How long will the string pointed to by the returned const char* pointer available to my program? 回答1: As long as the class with rtti exists. So if you deal with single executable - forever. But for classes in a Dynamic Link Librariy it shifts a little. Potentially you can unload it. 回答2: The memory returned by type_info::name() will be available for the application's

How do I access Delphi Array Properties using RTTI

孤者浪人 提交于 2019-12-10 13:13:16
问题 I'm familiar with using Delphi RTTI to access "simple" properties (ints/enums/strings, etc) but I cannot grasp how to work with Array properties. I'm starting by looking for array equivalents for the GetPropValue/SetPropValue calls. I'd expect to see similar ones to these, but taking an extra "index" parameter, but can't seem to find anything in the typinfo unit help. 回答1: Arrays and array properties can't have RTTI for them up to D2009. But when Barry Kelly spoke at the Delphi Live

Building and evaluating expressions using Delphi RTTI

断了今生、忘了曾经 提交于 2019-12-10 12:18:58
问题 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 : string; published property Weight : Double read fWeight write fWeight; property Height : Double read fHeight write fHeight; property Name : string read fName write fName; end; And i have a routine which will evaluate the animal with the supplied expression function

Delphi 2010: whatever happened to TRTTIConstructor?

跟風遠走 提交于 2019-12-10 03:32:26
问题 I've got two questions (of which at least one is regarding RTTI in D2010 and dynamic instancing) I was reading what appears to be the foils for a conference talk by Barry Kelly, and found on p. 13 something that looked really interesting: TRTTIConstructor.Invoke . In an adjacent bullet point, one finds "Dynamically construct instances without needing virtual constructors and metaclasses". This seems like a great feature (and exactly what I need, btw)! However, when I look in the D2010 docs

Can RTTI interrogate types from project code at designtime?

偶尔善良 提交于 2019-12-10 02:04:10
问题 I would like to use RTTI to examine the types contained within project source files at designtime rather than runtime. To the best of my knowledge this is unsupported but the discussion in the comments of this question indicate that it is possible and has been for several Delphi versions. This is the first time I have heard of this functionality being available though and as yet I have been unable to reproduce it for myself. Here is my test example. It uses a simple TListBox descendant

Static cast vs. dymamic cast for traversing inheritance hierarchies

假装没事ソ 提交于 2019-12-09 18:24:07
问题 I saw one book on C++ mentioning that navigating inheritance hierarchies using static cast is more efficient than using dynamic cast. Example: #include <iostream> #include <typeinfo> using namespace std; class Shape { public: virtual ~Shape() {}; }; class Circle : public Shape {}; class Square : public Shape {}; class Other {}; int main() { Circle c; Shape* s = &c; // Upcast: normal and OK // More explicit but unnecessary: s = static_cast<Shape*>(&c); // (Since upcasting is such a safe and

Get the offset of a field in a delphi record at runtime

烈酒焚心 提交于 2019-12-08 21:05:37
问题 Given a record type: TItem = record UPC : string[20]; Price : Currency; Cost : Currency; ... end; And the name of a field as a string , how can I get the offset of that field within the record? I need to do this at runtime - the name of the field to access is decided at runtime. Example: var pc : Integer; fieldName : string; value : Currency; begin pc := Integer(@item); // item is defined and filled elsewhere fieldName := Text1.Text; // user might type 'Cost' or 'Price' etc Inc(pc,

Compiler agnostic runtime type information?

时光总嘲笑我的痴心妄想 提交于 2019-12-08 14:32:29
问题 How can compiler agnostic run-time type information be generated and compared? In particular, how can this be done for function pointer types? For example, the following program contains a type error. It cannot be detected at compile-time. How can it be detected at run-time? How can such errors be detected in general? main.cpp #include <iostream> #include <dlfcn.h> typedef void (*FooPtrType)(); typedef void (*BarPtrType)(); int main() { const auto dll = dlopen("functions.dylib", RTLD_LAZY);

Boost Serialization of simple class with RTTI turned Off (-fno-rtti)

社会主义新天地 提交于 2019-12-07 22:46:33
问题 I am trying to serialize a simple class with Plain-old-Data types using boost serialization. However, my only requirement is that I cannot use RTTI. Thus I am compiling with -fno-rtti using gcc 4.4.1 for ARM Linux with latest Boost 1.47 library. So here is my class: #include <boost/archive/xml_oarchive.hpp> #include <boost/archive/xml_iarchive.hpp> class libNemoMemento { friend class boost::serialization::access; private: template<class Archive> void serialize(Archive & ar, const unsigned int