游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1651|回复: 0

静态函数派生类中重定义问题

[复制链接]

36

主题

109

帖子

111

积分

注册会员

Rank: 2

积分
111
发表于 2008-7-16 09:12:00 | 显示全部楼层 |阅读模式
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,重定义应该没有什么意义,但是人家这样写肯定是有道理的,不知道谁能解释下。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-21 23:54

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表