.netmanaged-c++

Create a class without a constructor in .NET managed C++


I want to create a class to hold my specific variable like a bitmap. I must include this class and can use the bitmap without creating an instance of this class.

How can I do this?


Solution

  • This is assuming you meant C++/CLI and not managed C++, as they are fairly different languages.

    public ref class MyStaticClass abstract sealed {
         // static members here
    };
    

    That will create a static class that can't be instantiated, holding whatever static members you need.

    If your class will only be holding static data, I would recommend doing it this way, via a static class. If you intend on letting the class be instantiated (it looks from your question that this isn't the case), you shouldn't declare it with abstract sealed and simply make the member you want to access without an instance, static.