VC++中::作用是什么?
在下列代码
BOOL CDbAdoDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
m_strConnection=_T("Provider=MSDASQL.1;Data Source = STU");
m_strCmdText=T("select * from addresses");
m_pRs=NULL;
m_piAdoRecordBinding=NULL;
::CoInitialize(NULL);
return TRUE;
}
中
::CoInitialize(NULL)前面的::作用是什么?谢谢指教
[解决办法]
该函数是全局的API函数,而不是CDbAdoDoc的成员函数
[解决办法]
域限定符号...说明你的这个东西是在哪个域的。
BOOL CDbAdoDoc::OnNewDocument()
说明了函数OnNewDocument()是属于域CDbAdoDoc(这里的这个应该是一个类)
::CoInitialize(NULL)用法就说明这个是属于全局域的..是全局的API函数,如果你在自己声明过的相同名字的函数(例如在本文件或者本文件引用的库,或者本类中),那么这样做就可以显式调用全局的这个函数,而不是自己声明的函数。
[解决办法]
是不是 和 this-> ...........
[解决办法]
域限定符号。如果前面没用东西 则表示全局作用域,例如: ::CoInitialize
前面有东西表示具体的作用域 如:CDbAdoDoc:: 表示在那个类里面
[解决办法]
全局名字空间
[解决办法]
Global Names
A name of an object, function, or enumerator is global if it is introduced outside any function or class or prefixed by the global unary scope operator (::), and if it is not used in conjunction with any of these binary operators:
Scope-resolution (::)
Member-selection for objects and references (.)
Member-selection for pointers (–>)