|
|
class A
{
public:
A(int a):count(a){};
static int getage(){return age;}
protected:
int count;
static int age;
}
int A::age=0;
class B:public A
{
public:
B(int a)A(a){}
static int getage(){return age}
..........................
......................
}
我经常看到类似上面的用法,也就是一个派生类中会重新定义一次基类中的同样的静态函数(getage),在我感觉他们都是返回基类中的静态成员age,重定义应该没有什么意义,但是人家这样写肯定是有道理的,不知道谁能解释下。 |
|