文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>虚函数在构造函数中失效

虚函数在构造函数中失效

时间:2010-03-27  来源:qytan36

Remeber first: virtual table's construction isn't finished before the class's constructor, so the polymorphism is unavailable during the construction of the class.

e.g

 

class Base
{
public:
    Base() { sayHello(); }
    virtual void sayHello() { cout << "Base says hello\n"; }
};

class Derived : public Base
{
public:
    void sayHello() { cout << "Derived says hello\n"; }
};

int main(int argc, char *argv[])
{
    Derived d;
    return 0;
}

输出结果:
   Base says hello


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载