This is for C++/CLI, not ".NET Managed Extensions for C++" aka C++.NET. Don't use the Managed Extensions (Visual Studio 2002-2003), they're buggy.
ref class Singleton
{
private:
Singleton() {}
Singleton(const Singleton%) { throw gcnew System::InvalidOperationException("singleton cannot be copy-constructed"); }
static Singleton m_instance;
public:
static property Singleton^ Instance { Singleton^ get() { return %m_instance; } }
};
As for "across multiple files", other compilation units in the same project use #include
, other assemblies use a reference (or #import
). Then there won't be any redefinition issues.