Re: mixed struct with constant and variable data

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alberto Poblacion

    Re: mixed struct with constant and variable data

    "markus wolfgart" <markus.wolfgar t@dlr.dewrote in message
    news:6nfpkqFjok 6jU1@mid.dfncis .de...
    public struct PFD_Order_T
    {
    [...]
    public const string key_order_id = "order_id";
    [...]
    PFD_Order_T PfdOrder;
    [...]
    pfdorder.order_ id =
    extract_from_or der_line(fileLi ne,pfdorder.key _order_id); <=== My problem
    [...]
    I could not select my constant part of my struct like I demonstrate above.
    Means pfdorder.key_or der_id is for me not visible in vs2005 where
    as pfdorder.order_ id could be selected.
    >
    Any hints whats wrong with my definition of the struct PFD_Order_T.
    Nothing wrong with the struct, but with the code that accesses the
    constant. The "const" is automatically considered "static", which means that
    you have to access it like a static member, using the name of the struct
    instead of the instance:

    PFD_Order_T.key _order_id instead of pfdorder.key_or der_id.



  • markus wolfgart

    #2
    Re: mixed struct with constant and variable data

    Alberto Poblacion schrieb:
    "markus wolfgart" <markus.wolfgar t@dlr.dewrote in message
    news:6nfpkqFjok 6jU1@mid.dfncis .de...
    >public struct PFD_Order_T
    >{
    >[...]
    > public const string key_order_id = "order_id";
    >[...]
    > PFD_Order_T PfdOrder;
    >[...]
    > pfdorder.order_ id =
    >extract_from_o rder_line(fileL ine,pfdorder.ke y_order_id); <=== My problem
    >[...]
    >I could not select my constant part of my struct like I demonstrate
    >above. Means pfdorder.key_or der_id is for me not visible in vs2005 where
    >as pfdorder.order_ id could be selected.
    >>
    >Any hints whats wrong with my definition of the struct PFD_Order_T.
    >
    Nothing wrong with the struct, but with the code that accesses the
    constant. The "const" is automatically considered "static", which means
    that you have to access it like a static member, using the name of the
    struct instead of the instance:
    >
    PFD_Order_T.key _order_id instead of pfdorder.key_or der_id.
    >
    >
    >
    Thanks Alberto for your reply.

    My understanding was that every object of type PFD_Order_T created by
    the new operator is a clone of my struct 'PFD_Order_T' placed in memory.
    Is in this case every constant part of my struct only one time allocated
    in the memory, whereas the dynamic part will be created every time I use
    the new operator?

    My intension was to bundle the keys for data extraction with the
    structure where my dynamic data will be stored.

    But when I have to use an other name to access my keys then to access my
    data, which sense makes it to encapsulate my keys and my data in one
    structure.

    Should I separate the constant keys (patterns) from my extracted data?


    Bye

    Markus




    Comment

    • Alberto Poblacion

      #3
      Re: mixed struct with constant and variable data

      "markus wolfgart" <markus.wolfgar t@dlr.dewrote in message
      news:6njmjlFlue 35U1@mid.dfncis .de...
      My understanding was that every object of type PFD_Order_T created by
      the new operator is a clone of my struct 'PFD_Order_T' placed in memory.
      Is in this case every constant part of my struct only one time allocated
      in the memory, whereas the dynamic part will be created every time I use
      the new operator?
      Yes, the dynamic parts are allocated each time, but since the "const" is
      invariable, it is treated as "static", that is, it is allocated a single
      time.
      My intension was to bundle the keys for data extraction with the
      structure where my dynamic data will be stored.
      >
      But when I have to use an other name to access my keys then to access my
      data, which sense makes it to encapsulate my keys and my data in one
      structure.
      It would make sense if you wanted to encapsulate the whole functionality
      together: the data, the keys, and the method that operate on the data and
      keys. However, this is more typically done with a class instead of a struct.
      Should I separate the constant keys (patterns) from my extracted data?
      Possibly, depending on how your program is intended to operate. It may
      make sense to create a "decoder" class which has the const keys and the
      methods that access the data by means of those keys, and then create a very
      simple separate struct to contain only the data values upon which the class
      methods operate. These stucts would not contain any methods or constants.
      The class could be entirely static, if it doesn't need to maintain any
      state.

      Comment

      Working...