void foo (int x)
{
struct A { static const int d = 0; }; // error
}
除了来自标准的参考之外,这背后是否有任何动机禁止static内部类中的字段?
error: field `foo(int)::A::d' in local class cannot be static
编辑:但是,static允许成员函数。对于这种情况,我有一个用例。假设我只想foo()为 POD 调用,那么我可以像这样实现它,
template<typename T>
void foo (T x)
{
struct A { static const T d = 0; }; // many compilers allow double, float etc.
}
foo()应该只通过 POD(如果static允许)而不是其他数据类型。这只是我想到的一个用例。