【问题标题】:C++ polymorphism in mfcmfc 中的 C++ 多态性
【发布时间】:2016-06-28 05:12:12
【问题描述】:

有些东西我不明白。

我们重写了 InitInstance okey 但在 CwinApp 类中有许多虚函数 并创建应用程序对象,这不是指针。这是对象。

这不符合 c++ 多态性规则

我有错吗?

class CMyApp : public CWinApp {
public:
    virtual BOOL InitInstance(void);//override
};
CMyApp theApp; //then create object

【问题讨论】:

    标签: c++ c mfc


    【解决方案1】:
    CMyApp theApp;
    

    如果静态(即在编译期间)类型与动态(即在运行时)类型不同,则称对象是多态的。在上面的语句中,theApp的静态和动态类型是相同的,即CMyApp

    CWinApp *polyApp = new CMyApp();
    

    在上述情况下,polyApp 静态类型为CWinApp,动态类型为CMyApp

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-24
      • 1970-01-01
      相关资源
      最近更新 更多