Jump to content

Runtime property

- - - - -

  • Please log in to reply
1 reply to this topic

#1
jaiii

jaiii

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
Hay,

is it possible add propertys to class in runtime?

for example:

in design time I have empty class:
class MyClass
{

};

can I add to this class __propertis and methods in runtime ?

Thank very much .

Bye.

#2
Groogy

Groogy

    Programmer

  • Members
  • PipPipPipPip
  • 183 posts
Well not like the normal static way but you could do it by a form of interface with functions and storing the properties in a container. You could fix this with dynamic memory allocation but this method will be more static and let you work without pointers and the problems that come with it.


class MyClass {

public:

  struct Property {

     enum {

        // All different types identifier here

     } type;

     union {

        // All memory storage for the different types.

     } data;

  };

  

   // You can also do several overloaded versions for each type you accept.

   void SetProperty(std::string name, Property prop);

   Property GetProperty(std::string name);

private:

  std::map<std::string, Property> myProperties;

};


I always follow "Keep-It-Simple-Stupid" ^^
My Code Blog - My Github - Ascension Project - Madness Script Project - Simple-Garbage-Collector Project
There is bound to be something useful somewhere.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users