这里我有:如何在函数中定义一个类的静态成员?
class X {
public:
static int shared_arr[];
static void alloc_and_init() {
// Since any static variables defined in the function are allocated some space.
// So can I define X::shared_arr here (using the space the static variable for X::shared_arr)?
// I think it would be a convenient way to make an approach of some basic memory allocation and initialization.
}
};
你应该花一些时间在C++上写一本好书。您的'shared_arr'成员缺少类型,'[]'是数组修饰符给出的不完整类型,不能在类定义中使用。从更广泛的角度来看,几乎可以保证针对您要解决的任何问题提供更好的解决方案。 – 2012-03-19 14:22:01
@KerrekSB:该成员是一个“静态”成员。我相信你实际上可以在成员的*声明中使用不完整的类型。 – 2012-03-19 14:24:37
@KerrekSB对不起。我忘了输入。 – Determinant 2012-03-19 14:25:18