静态数据成员在 C++ 中是否可以输入其容器类型?
我在 C# 或其他语言中使用过类似的东西。
// C#, but I can't remember correctly. Just assume like a pseudo code.
class A
{
public int b;
public A(int newB)
{
b = newB
}
public static const A a1 = A(1);
public static const A a2 = A(2);
public static const A a3 = A(3);
}
C++ 中有类似的东西吗?或者有什么推荐的方法来做到这一点?我这样做只是为了在其类名中组织 a1
、a2
、a3
。
I was used something like this in C# or other languages.
// C#, but I can't remember correctly. Just assume like a pseudo code.
class A
{
public int b;
public A(int newB)
{
b = newB
}
public static const A a1 = A(1);
public static const A a2 = A(2);
public static const A a3 = A(3);
}
Is there equivalent of this in C++? Or any recommended way to do this? I do this for just to organize a1
, a2
, a3
within its class name.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下 C++ 代码与您的 C# 代码等效:
The following C++ code is equivalent to your C# code: