为什么在函数前使用:: [英] Why we are using :: before a function

查看:58
本文介绍了为什么在函数前使用::的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我看过VC ++代码.

:: FindNextFile().这是MFC函数.我们可以不使用"::"来调用此函数吗?

运算符.如果那为什么我们使用::运算符.我也看到了相同的调用

用户定义函数中的过程.它是

Hi all,

I have seen a VC++ code.

::FindNextFile().It is an MFC function.Can we call this function without using "::"

operator.If then why we are using :: operator.Also i have seen same calling

procedure in an user defined function.And it is

::DisplayMessage(&m_RichEditLog,csMessage,1);


相应的.CPP文件是


And the corresponding .CPP file is

------------------------------------------------------------------------------------
------------------------------------------------------------------------------------
DWORD CALLBACK RichEditStreamInCallBack(DWORD dwCookie,LPBYTE pbBuff,LONG cb, LONG *pcb)
{
	return 0;
}
void DisplayMessage(CRichEditCtrl * pRichEdit,const CString &cstrMessage,int nFlags/*=FALSE*/)
{

	
	
}

void SaveText(CRichEditCtrl * pRichEdit,const CString & strFile)
{
	
}

DWORD CALLBACK RichEditStreamOutCallBack(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{

	return 0;
}

------------------------------------------------------------------------------------------------------------------------------------------------------------------------


.h文件是


.h file is

------------------------------------------------------------------------------------------------------------------------------------------------------------------------

DWORD CALLBACK RichEditStreamInCallBack(DWORD dwCookie,LPBYTE pbBuff,LONG cb, LONG *pcb);

void DisplayMessage(CRichEditCtrl * pRichEdit,const CString & cstrMessage,int nFlags/*=FALSE*/);

void SaveText(CRichEditCtrl * pRichEdit,const CString & strFile);
static DWORD CALLBACK RichEditStreamOutCallBack(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb);

------------------------------------------------------------------------------------------------------------------------------------------------------------------------


请帮帮我.

在此先感谢


Please help me.

Thanks in advance

推荐答案

这在类中具有与Win32 API(全局函数)函数名称中的函数名称相同的函数的情况下使用.例如,在Visual Studio文件"AFXWIN.h" 中,我们有一个名为AfxMessageBox()的函数.假设您有一个CMyClass类.它还具有一个称为AfxMessageBox()的函数.您的班级标题包含文件"AFXWIN.h".

This is used in situations where you have function in your class with its name same as one in win32 API(global function) function name. for example, within the Visual studio file "AFXWIN.h", we have a function called AfxMessageBox(). suppose you have a class CMyClass. It also has a function called AfxMessageBox(). your class header includes the file "AFXWIN.h".

#include <afxwin.h>
....
....
class MyClass
{
....
int AfxMessageBox(...)
{
 //DO SOMETHING
}
....
}
.........</afxwin.h>



当您从类中调用函数AfxMessageBox()时,它将指向您类中的成员函数AfxMessageBox().但是,如果要调用MFC函数AfxMessageBox()怎么办?
那个时候你叫它



When you call the function AfxMessageBox() from your class, it will point to the member function AfxMessageBox() in your class. But what if you want to call the MFC function AfxMessageBox()??.
That time you call it like

::AfxMessageBox()


这篇关于为什么在函数前使用::的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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