1.静态成员函数的地址可用普通函数指针储存,而普通成员函数地址需要用 类成员函数指针来储存。举例如下:
class base{static int func1();
int func2();
};
int (*pf1)()=&base::func1;//普通的函数指针
int (base::*pf2)()=&base::func2;//成员函数指针
2.静态成员函数不可以调用类的非静态成员。因为静态成员函数不含this指针。
3.静态成员函数不可以同时声明为 virtual、const、volatile函数。举例如下:
class base{
virtual static void func1();//错误
static void func2() const;//错误
static void func3() volatile;//错误
};
最后要说的一点是,静态成员是可以独立访问的,也就是说,无须创建任何对象实例就可以访问。
静态函数使用:
class CommonPart
{
private:
CommonPart(void) {};
static BOOL ReadShapeSortsConfig(const int &dataType,int iFilter,vector<CString> &strSorts,vector<vector<CString>> &strShapes,vector<std::pair<int,CString>> &shapeId);
}
BOOL CommonPart::ReadShapeSortsConfig(const int &dataType,int iFilter,vector<CString> &strSorts,vector<vector<CString>> &strShapes,vector<std::pair<int,CString>> &shapeId)
调用:
CommonPart::ReadShapeSortsConfig(nType,m_invokeType,strSorts,shapesType,shapeId);