,我們可以有一個虛擬的靜態方法(在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
所以我想答案是否定的,但爲什麼呢?
感謝, 羅恩
啊哈,那麼靜態意味着*這個不存在,虛擬意味着該方法有一個這個指針。兩者的結合是矛盾的。尼斯:)謝謝 –