Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
've used the Visual Studio project wizards to create some basic GUI apps with VC++.

When debugging, I've noticed the native MFC code to be riddled with syntax such as this:

derivedClass::Method()

{

baseClass::Method();

}

For exmaple, I created a simple Windows app titled MFCApp.

The wizard naturally creates classes derived from CwinAppEx, CDocument and CView, called, CMFCAppAPP, CMFCAppDoc and CMFCAppView.

Inside the implementation of these derived classes I frequently encounter code like:

void CMFCAppDoc::AssertValid() const
{
CDocument::AssertValid();
}
and

void CMFCAppView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
I am very perplexed by this because according to all the books I've read and my experience, you can only call a base class method via the scope resolution operator, if and only if that said method is Static, which in all these exaples I have encountered in the MFC code, that is not true. The compiler should flag a compilation error C2352 a link to which is here:

https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/compiler-error-c2352?f1url=https%3A%2F%2Fmsdn.microsoft.com%2Fquery%2Fdev15.query%3FappId%3DDev15IDEF1%26l%3DEN-US%26k%3Dk(C2352)%26rd%3Dtrue&view=vs-2017

Please help me because I'm highly perplexed.

Many Thanks, Rez

What I have tried:

This a question so i have not tried anything.
Posted
Updated 27-Sep-18 4:31am

This are the calls of the base class implementation of the methods. Dont ferget that these code is in the class instance code and not outside.

In your link it is different sample code. Outside of the class and the second is a static function. Static means global unique, but in the name space of the class and so not a member function.
 
Share this answer
 
Thanks for your reply.

Then please tell me why the following does not work ?

class base

{

public:
virtual void OddFunction() const;
};

class Derived: public base
{
public:
virtual void  OddFunction() const;
};

Derived OddFunction()
{
base::OddFunction();
}

int main()
{
Derived d;
       d.OddFunction();

}

Many Thanks,  Rez
 
Share this answer
 
Comments
Rick York 27-Sep-18 11:38am    
If you want to ask a question about someone's solution you should use the "Have a question of comment?" button below that solution. you should not post your question as another solution.
Rick York 27-Sep-18 11:45am    
Your code sample in this "Solution" has numerous syntax issues in it. Here it is with those corrected :
class base
{
public:
    virtual void OddFunction() const
    {
        // this needs to have some implementation if it is going to be called
    }
};

class Derived: public base
{
public:
    virtual void OddFunction() const;
};

void Derived::OddFunction()   // must have a return type and class specification
{
   base::OddFunction();
}

int main()
{
    Derived d;
    d.OddFunction();
}
KarstenK 28-Sep-18 3:07am    
Rick is right and plz read about the virtual keyword. It is somehow a placeholder which needs some implementation. Another interesting topic are interfaces.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900