为什么the following code无法正常工作?为什么派生类不能访问基类静态方法?
class A
{
static void Method() { std::cout << "method called."; }
};
class B : public A
{
// Has a bunch of stuff but not "Method"
};
int main()
{
B::Method();
}
我知道我可以使它通过添加以下到B的工作,但是这将是很好,如果这是没有必要的,尤其是如果有从A派生几类
static void Method() { A::Method(); }
@jthill你是对的。如果它是公开的,它工作得很好。谢谢。 – sgryzko