But then you can't do something like...
enum eLOGGING_LEVEL
{
LOG_BASIC = 0,
LOG_NORMAL = LOG_BASIC + 1,
LOG_EXHAUSTIVE = LOG_NORMAL + 1,
} eLOGGING_LEVEL;
class CLog
{
int m_DefaultLoggingLevel = LOG_BASIC;
CLog()
{
// contruction code here
}
CLog( int nLoggingLevel )
{
m_DefaultLoggingLevel = nLoggingLevel;
}
// rest of the class where some method may use
m_DefaultLoggingLevel
}
Now some other class which contains a CLog object wants to do this...
void CreateNewLog()
{
CLog myLog(LOG_NORMAL);
}
The problem being if you have to wrap up all yours apps constants
into a class, you can't use them when initialising variables in those
classes.
At least in VB you have an option to put it in a Module... C++ just
lets you do whatever, and perhaps is a bit loose, but people should
be taught the proper way of doing things, rather than stopping
everyone from doing something they think is bad style.
Dmitriy Lapshin said:
Hello Daniel,
Speaking of globally accessible constants, a common practice is to
group them into sealed classes having private constructors:
public sealed class FieldLimit
{
private FieldLimit()
{
}
public const int FirstName = 90;
public const int Email = 64;
}
Hope this is not terrible and it, in my opinion, makes your code
look more readable.
--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Unit Testing and Integration Environment
http://x-unity.miik.com.ua
Deliver reliable .NET software
Daniel Bass said:
how do i declare a global variable in c#.net? it's like it want's
everything in classes... there are times when globals are good,
like having constants in a program which apply to several
layers/objects/etc...
or does it expect me to create a singleton global class structure?
surely it's not that terrible.