This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C++: Global classes: prefer static data or not?

Hi,
very sorry if this question should be too picky ... .

I have quite a bit of large "global classes" in my multi-module C++ software. (I mean a class without constructor/destructor, which is used exactly one time in the software - it is defined "globally").

As it is used only one time, I could specify the variables / functions as static or not. I was wondering, which way would create tighter code. According to my investigations I have the following rules now:
- Functions should be static, except inline functions - these must NOT be static (otherwise they are not inlined any more).
- Public data variables, which are heavily used outside class functions, should preferably be defined static.
- Private data variables, which are mainly used inside class functions, should preferably be defined non-static.

Could some C++ expert have a look at these rules and comment them? (ok, quite ok or complete nonsense?)

PS: In some C++ languages, it seems to be possible to define a complete class as static:

static class TestClass{
...
};

As I see, this is NOT possible in Keil C++, or am I wrong?

0