2
这里是例子:有同名类静态方法作为另一个类
struct A
{
A(const int a):b(a)
{
}
int b;
};
struct B
{
B() : a(5)
{
}
static void A()
{
}
A a;
};
int main()
{
B::A();
}
而且编译器错误是:
a9.cpp:19: error: ‘A’ does not name a type
a9.cpp: In constructor ‘B::B()’:
a9.cpp:24: error: class ‘B’ does not have any field named ‘a’
我使用在Fedora 9的gcc 4.3.0。
有人可以解释为什么编译器抱怨吗? 如果可能,请参考标准。
感谢
是的,我想出了静态方法名称会影响类名的难题,但它是代码还是编译器错误?另外,你能否说出标准中的含义? – 2010-11-09 15:05:20
我添加了一些标准,我认为可以解释这种行为。对我来说,看起来很自然,你的代码不起作用。 – 2010-11-10 13:39:51