2015-11-03 99 views
-1

場景:我想在子中使用父方法。是否有可能創建一個包含兩個對話框類的解決方案?CDialog類的父 - 子實現

//Parent is created using class wizard(inherited from CDialog) 
class CDlgParent : public CDialog 


//Child class created using class wizard(inherited from CDialog) and then 
    //changed the inheritance 
class CDlgChild : public CDlgParent 
+0

1.我需要的是兩個對話框類,一個是父類,另一個是父類繼承。子對話框使用基本方法。任何幫助表示讚賞。 – RENN

+0

是的,這是可能的。你試過了嗎?這是真正簡單的過程。 –

回答

0

只是爲了舉例

class A 
{ 
private: 
    void privateMethod(){} 
protected: 
    void protectedMethod(){} 
public: 
    void publicMethod(){} 
}; 
class B : public A 
{ 
    void methodB() 
    { 
     //privateMethod(); 
     protectedMethod(); 
     publicMethod(); 
    } 
}; 

只是在你的代碼複製這一點,你會看到,它會編譯。
如果您取消註釋行,它不會編譯了,給了一個錯誤,如:

無法訪問私有成員在類「A」

所以,唯一的,你不能從使用方法聲明B,繼承自A,是私有方法,其他所有方法都可以正常使用