有人可以向我解释这个Microsoft MFC语法! ! ! ! ! [英] Can someone please explain this Microsoft MFC syntax to me ! ! ! ! !

查看:67
本文介绍了有人可以向我解释这个Microsoft MFC语法! ! ! ! !的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Visual Studio项目向导用VC ++创建一些基本的GUI应用程序。



调试时,我注意到了本机MFC代码语法如下:



derivedClass :: Method()



{



baseClass :: Method();



}



例如,我创建了一个名为MFCApp的简单Windows应用程序。



该向导自然地创建派生自CwinAppEx,CDocument和CView的类,称为CMFCAppAPP,CMFCAppDoc和CMFCAppView。



在这些派生类的实现中,我经常遇到如下代码:



void CMFCAppDoc :: AssertValid ()const

{

CDocument :: AssertValid();

}





void CMFCAppView :: Dump(CDumpContext& dc)const

{

CView :: Dump(dc);

}

我对此感到非常困惑,因为根据我读过的所有书籍和我的经验,你只能通过范围解析算子调用基类方法,如果和只有当所述方法是静态时,在我在MFC代码中遇到的所有这些问题中,这都是不正确的。编译器应该标记编译错误C2352链接到这里:



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)% 26%%3Dtrue& view = vs-2017



请帮帮我,因为我非常困惑。



非常感谢,Rez



我尝试了什么:



这个一个问题,所以我没有尝试任何东西。

'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.

推荐答案

这是方法的基类实现的调用。不要忘记这些代码是在类实例代码而不在外面。



在你的链接中它是不同的示例代码。在类之外,第二个是静态函数。静态意味着全局唯一,但在类的名称空间中,因此不是成员函数。
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.


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


这篇关于有人可以向我解释这个Microsoft MFC语法! ! ! ! !的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆