1
#include <iostream>
using namespace std;
class MyClass
{
private:
static int x;
static int calc(int a, int b)
{
cout << "chekcing !! ";
return b * a;
}
};
int MyClass::x = 1;
int main()
{
MyClass::calc(1,2);
MyClass::x += 3;
return 0 ;
}
問題:據我所知靜態成員不是類的一部分,那麼爲什麼我們有檢查訪問說明符?爲什麼檢查訪問規範的靜態數據成員
靜態**成員**不是成員? – Mat 2013-05-08 07:05:42
靜態成員是類的一部分,但不是類的實例的一部分。 – Arun 2013-05-08 07:06:36
當然他們是班級的一部分。它們對於所有實例都是一樣的。 – 2013-05-08 07:06:41