Program-wide data, C++
- by bobobobo
I'd like to make program-wide data in a C++ program.
The easiest way to do it in C# is just public static members.
C#:
public static class DataContainer
{
public static Object data1 ;
public static Object data2 ;
}
In C++ you can do the same thing
C++ global data way#1:
class DataContainer
{
public:
static Object data1 ;
static Object data2 ;
} ;
Object DataContainer::data1 ;
Object DataContainer::data2 ;
However there's also extern
C++ global data way #2:
class DataContainer
{
public:
Object data1 ;
Object data2 ;
} ;
extern DataContainer * dataContainer ; // instantiate in .cpp file
Which is better, or possibly another way which I haven't thought about?