zoukankan      html  css  js  c++  java
  • 虚函数(2)

    /*虚函数(2)*/

    class CEmployee 
    {
    public:
        CEmployee()
        {
            nTemp = 9;
        }
        virtual ~CEmployee();
    public:
        int nTemp;
        virtual void ShowWage(void)
        {
            cout << this << ":
    员工发工资方法" << endl;
        }
    };

    class CItemManager : public CEmployee 
    {
    public:
        CItemManager();
        //
    虚函数表中的第一个虚函数,写在第一个,所以表中也会是第一个(0)
        virtual ~CItemManager();
    public:
        //
    虚函数表中的第二个虚函数 写在第二个,所以表中也会是第二个(1)
        virtual void ShowWage(void)
        {
            cout << this << ":
    项目经理发工资方法" << endl;
        }
    };


    int main(int argc, char* argv[])
    {
        CEmployee *theEmployee1 = NULL;
       
        theEmployee1 = new CItemManager;
        //
    调用虚函数
        theEmployee1->ShowWage();

        if (theEmployee1)
        {
            //
    这里会调用析构函数,也是虚函数
            delete theEmployee1;
            theEmployee1 = NULL;
        }
    }

    Snap1

  • 相关阅读:
    ◆ C++中通过溢出覆盖虚函数指针列表执行代码
    关于在OnTimer中连续弹出对话框的讨论
    SetTimer
    Windows内核对象
    日志收缩
    暴力求值
    低级问题
    函数限制
    字符串找字段和表
    android错误提示说明汇总
  • 原文地址:https://www.cnblogs.com/w413133157/p/1657882.html
Copyright © 2011-2022 走看看