在 .NET 托管 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是假设您指的是 C++/CLI 而不是托管 C++,因为它们是相当不同的语言。
这将创建一个无法实例化的静态类,其中包含您需要的任何静态成员。
如果您的类仅保存静态数据,我建议通过静态类这样做。如果您打算让该类实例化(从您的问题来看情况并非如此),您不应该使用
abstract seal
声明它,而只需将您想要访问的成员设置为一个实例,静态的。This is assuming you meant C++/CLI and not managed C++, as they are fairly different languages.
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.