I am stuck with a doubt! I have been working with MFC based applications for sometime. Decided to read up some theory to strengthen my fundamentals. Naturally, I was reading MFC concepts as well as C++ basics. What struck me was the way we use VIRTUAL in both.
In C++, there goes a standard way to use virtual functions.
- There is a Base class B having a function func() and its derived class D also uses/implements the function func(). If a function creates objects of both B and D and calls this func() through a pointer to B, the base class version of this function will be called UNLESS we declare func() as virtual .right??? So if we want to call func() from D's implemetation, we declare func() as virtual in Base class B , pass a reference of D's object to base class B's pointer and then call func() thru this pointer. I guess i got this right so far???
Now, how do we go about it in MFC(which is also supposed to be C++ at the end of the day)? From what I have used so far..i use virtual funcs like this.
Class CDialog has 3 virtual functions. Lets take OnInitDialog() as the example.
Code: CPP
class CDialog
{
-----
virtual BOOL OnInitDialog();
-----
}
Code: CPP
eg class CMyDlg : public CDialog
{
protected:
virtual BOOL OnInitDialog();
}
Then, how do i call OnInitDialog()??
Answer: I do it THROUGH DoModal().
Code: CPP
eg: OnBtOpenDlg()
{
CMyDlg myDLg;
if(myDlg.DoModal()==ID_OK)
{ --------}
}
Am i missing something or are they implemented differently in C++ and MFC programming????????

