【发布时间】:2012-03-19 14:19:04
【问题描述】:
这里有:
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成员缺少类型,[]作为数组修饰符提供了一个不完整的类型,无法在类定义中使用。从更广泛的角度来看,几乎可以保证对于您要解决的任何问题都有更好的解决方案。 -
@KerrekSB:该成员是
static成员。我相信您实际上可以在成员的声明中使用不完整的类型。 -
@KerrekSB 对不起。我忘记输入了。
-
@DavidRodríguez-dribeas:哦,很好,我没想到这一点——有道理。
标签: c++ static-methods static-members