我被要求为以下问题提供解决方案:
有一个结构定义了一些 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];
有什么建议吗?