Search code examples
c++-cliglobal-variablesmanaged-c++

Global objects of Managed types


Is there any way to declare/define global/static objects of managed types ?


Solution

  • Although you can have static methods and members in managed code, .NET does not have any concept of a global or completely static object. You can have a class with all static members (and in C#, it can be called a static class, but this is a compiler construct).

    However, you can effectively do this via Singletons in C++/CLI. The same issues that exist with Singletons in C# map to C++/CLI when dealing with managed classes.