,我们可以有一个虚拟的静态方法(在C++)?我试图编译下面的代码 :
#include <iostream>
using namespace std;
class A
{
public:
virtual static void f() {cout << "A's static method" << endl;}
};
class B :public A
{
public:
static void f() {cout << "B's static method" << endl;}
};
int main()
{
/* some code */
return 0;
}
但是编译器说:
member 'f' cannot be declared both virtual and static
所以我想答案是否定的,但为什么呢?
感谢, 罗恩
啊哈,那么静态意味着*这个不存在,虚拟意味着该方法有一个这个指针。两者的结合是矛盾的。尼斯:)谢谢 –