473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Re: mixed struct with constant and variable data

"markus wolfgart" <ma*************@dlr.dewrote in message
news:6n************@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_order_line(fileLine,pfdorder.key_orde r_id); <=== My problem
[...]
I could not select my constant part of my struct like I demonstrate above.
Means pfdorder.key_order_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_order_id.

Nov 6 '08 #1
2 2250
Alberto Poblacion schrieb:
"markus wolfgart" <ma*************@dlr.dewrote in message
news:6n************@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_order_line(fileLine,pfdorder.key_ord er_id); <=== My problem
[...]
I could not select my constant part of my struct like I demonstrate
above. Means pfdorder.key_order_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_order_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


Nov 7 '08 #2
"markus wolfgart" <ma*************@dlr.dewrote in message
news:6n************@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.

Nov 7 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: mg | last post by:
Hi everybody... I am using Python API in order to create bindings. So, in the init function of my module, I create constants : PyMODINIT_FUNC initMyModule( void ) { PyObject* module =...
20
by: CoolPint | last post by:
While I was reading about const_cast, I got curious and wanted to know if I could modify a constant variable through a pointer which has been "const_cast"ed. Since the pointer would be pointing to...
15
by: Ramaraj M Bijur | last post by:
Hi All, Could anyone help me to resolve following problem in C the IDE used is Microsoft VC++, Please let me know the which option in VC++ will do the needful The problem statement:...
2
by: Dahab | last post by:
Hi, What is the best way to preserve variable data during postback? Using hidden server controls is a way, but there has to be something better. Thanks D.
1
by: slrj | last post by:
Can I use a local struct to store data in the "set" conatiner? If so, what is the correct method to do so? Compiler: Sun Studio 10 on Unix (Sun Solaris) #include<iostream> #include<set> ...
6
by: psbasha | last post by:
The following example shows the storing of the data and accessing the data from dictionary variable.The accessing of dictionary variable data is not a orderas what we are storing. Is my...
9
by: blangela | last post by:
Can somepoint me to a good discussion on the pros and cons of using #define versus a constant variable in your C+ application? Thanks, Bob
1
by: sbw | last post by:
I have a simple mailing list like this (below) and I want to produce a VERY simple address block using XSL for my newsletter. Just name, address, city-state-zip. That's all. So it prints the...
0
by: PauloD | last post by:
public struct Character_Items { public short Armor; public short Helm; public short WeaponL; public short WeaponR; public short Pants; public short Boots; public short Gloves; public short...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.