I have a question on how to avoid globals using classes:

I have this:

class cWorkElement
{
public:
....
.....
Privat:
...
...
}

And then i have an array of 100 pointers to this array.

cWorkElement *aMyElements[100];

The "problem" is, that i use some global variabels in this - and i was
wondering if its normal pratice to include theese in a class instead ?

Class cGlobalClass
{
public:
// global variables

cWorkElement *aMyElements[100];
}

Is this a smart way to do it ?

Thanks.

RE: Class & Global variables by anonymous

anonymous
Wed Mar 03 10:01:08 CST 2004



----- verbartime wrote: ----

I have a question on how to avoid globals using classes

I have this

class cWorkElemen

public
....
.....
Privat
...
...


And then i have an array of 100 pointers to this array

cWorkElement *aMyElements[100]

The "problem" is, that i use some global variabels in this - and i wa
wondering if its normal pratice to include theese in a class instead

Class cGlobalClas

public
// global variable

cWorkElement *aMyElements[100]


Is this a smart way to do it

Thanks

It depends on what you want and how secure you want your code to be. it is best practice to have your variables delcared in your your private class. If you are using inheritance, you should put the variables in the Protected section of the class. this way only derived classes will be able to access these variables. Otherwise you can put them in public section which will decrease the security and may even cause problems depending how the client programs of the class will access them.