Modify, edit or change a structure

 
Hello,

i try to find a answear if it is possible to change a defined structure, later maybe to add a new element to the struct?

Is it possible?

struct struct_ar                                      
{  
   string   fieldname;        // Name of the field, also for headline
   int      value_int;        // Value of field, integer
   double   value_double;     // Value of field, double
   string   value_string;     // Value of field, string   
};


maybe later i need a another structure element for example
float value_float;"

Is it possible to check if this element already exists in structure and if not, to add it?

Thanks!
 
ReLor2:
Hello,

i try to find a answear if it is possible to change a defined structure, later maybe to add a new element to the struct?

Is it possible?



maybe later i need a another structure element for example
float value_float;"

Is it possible to check if this element already exists in structure and if not, to add it?

Thanks!

of course you can edit a structure just as you can edit any code

 
ReLor2: Is it possible to check if this element already exists in structure and if not, to add it?

Structures and Classes are defined at compile time, not at run-time.

It is you as the coder, that looks at the code text and decides to "modify, edit or change" it.

It is not something that is done during the code execution or run-time.

 
Fernando Carreiro #:

Structures and Classes are defined at compile time, not at run-time.

It is you as the coder, that looks at the code text and decides to "modify, edit or change" it.

It is not something that is done during the code execution or run-time.

Hi,

i'm a little bit confused about the two answears, let me make a smal example.

struct struct_ar                                      
{  
   string   fieldname;        // Name of the field, also for headline
   int      value_int;        // Value of field, integer
   double   value_double;     // Value of field, double
   string   value_string;     // Value of field, string   
};
struct_ar  myarray[1];
start=0;
void OnTick()
{
        
        if(start==0)
        {
                //let me use the origin structure
                myarray[0].fieldname="abc";
                start++;
        }
        else
        {
                //Now i want to add a new element to the structure
                myarray[0].newfield="abc"; 
                //This is not possible and failed because the field "newfield" isnt in my structure.
                //Ist it possible to add a new element in a structure wich is defined in global scope?

        }
        
}
 
ReLor2 #: i'm a little bit confused about the two answears, let me make a smal example.

My answer is still the same. You are attempting to modify a structure at "runtime". Structures and Classes are defined when you compile the code. They cannot be changed when the code is executed.

 
There is no “newfield” in the structure.
Your code will not compile.
You must add it and recompile.
struct struct_ar                                      
{  
   string   fieldname;        // Name of the field, also for headline
   int      value_int;        // Value of field, integer
   double   value_double;     // Value of field, double
   string   value_string;     // Value of field, string   
};
 
ok, thanks a lot. that was my main question to know if it is possible to change a structure after compile it or not.
 
ReLor2 #: hat was my main question to know if it is possible to change a structure after compile it or not.

You have been told, four (4) times, not.

Reason: