【发布时间】:2012-10-08 21:22:23
【问题描述】:
我被要求为以下问题提供解决方案:
有一个结构定义了一些 int 参数:
struct B {
int a;
int b;
};
有人想将此结构定义为其他类中的 const 静态成员(不仅针对此class A - 其他类预计具有相同的一组常量)。
有人想将它们用作真正的整数常量:
// .h file
class A {
public:
static const B c; // cannot initialize here - this is not integral constant
};
// .cpp file
const B A::c = {1,2};
但不能使用这个常量来制作例如数组:
float a[A::c.a];
有什么建议吗?
【问题讨论】:
标签: c++ struct initialization constants member