【发布时间】:2014-04-07 22:45:15
【问题描述】:
为什么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 你是对的。如果它是公开的,它工作得很好。谢谢。
标签: c++ inheritance static-methods