“::“什么意思?
作用域前面没有类标识符是表示该变量是全局变量;
但下面的语句中是定义在程序中而不在任何一个类中;
UINT CWindow::findMessage=::RegisterWindowMessage(FINDMSGSTRING);
请问::RegisterWindowMessage中的::是干什么的?
问题点数:50、回复次数:19Top
1 楼shuizhongtu(水中兔)回复于 2002-07-26 17:06:15 得分 0
::是作用域分辨符,表示在作用域外调用Top
2 楼anothervip(Never ending... ...)回复于 2002-07-26 17:07:01 得分 0
他是一个api函数Top
3 楼hitxiang(木头)回复于 2002-07-26 19:03:05 得分 0
作用域外调用?
但它已经是全局变量了。外调上哪去调?
Top
4 楼jiangh_79_1(微星)回复于 2002-07-26 20:22:03 得分 5
最外层就最外层咯
在MFC中调用API本来就要这样调用的阿
有什么奇怪, 有问题吗?Top
5 楼hitxiang(木头)回复于 2002-07-26 20:43:11 得分 0
不好意 ^_^
不明白,你能讲具体些。什么是最外层?举个例子!!!!!!!!!Top
6 楼qhq800(清风笑)回复于 2002-07-26 20:51:29 得分 0
upTop
7 楼coolping(小平)回复于 2002-07-26 21:55:31 得分 0
You can tell the compiler to use the global identifier rather than the local identifier by prefixing the identifier with ::, the scope resolution operator.
:: identifier
class-name :: identifier
namespace :: identifier
The identifier can be a variable or a function.
If you have nested local scopes, the scope resolution operator does not provide access to identifiers in the next outermost scope. It provides access to only the global identifiers.
Example
// expre_ScopeResolutionOperator.cpp
// compile with: /EHsc
// Demonstrate scope resolution operator
#include <iostream>
using namespace std;
int amount = 123; // A global variable
void main() {
int amount = 456; // A local variable
cout << ::amount << endl // Print the global variable
<< amount << endl; // Print the local variable
}
The example above has two variables named amount. The first is global and contains the value 123. The second is local to the main function. The scope resolution operator tells the compiler to use the global amount instead of the local one.
Top
8 楼fqcd555(love violet)回复于 2002-07-26 22:17:45 得分 0
up 我从来没看过这东西(运算符)Top
9 楼fqcd555(love violet)回复于 2002-07-26 22:41:07 得分 0
作用域外调用
为区别在一个函数里所定义的局部变量
Top
10 楼HR0019(^BuleTooth^)回复于 2002-07-26 23:02:44 得分 0
这是一个双目作用域运算符用来表示类成员。Top
11 楼yspei(灵智上人)回复于 2002-07-26 23:04:05 得分 5
属于Window接口函数,可以直接调用,在程序中::是可以省略的,Windows API函数就是这样调用.Top
12 楼cywater2000(如果)回复于 2002-07-26 23:09:23 得分 10
如果调用此函数的类没有此同名成员函数,加不加 :: 效果是一样的
但是我们一般都加 :: 表示它是一个“全局”的(API)
如::GetWinApp()
这样做还有一个好处就是增强“可读性”Top
13 楼hitxiang(木头)回复于 2002-07-26 23:30:50 得分 0
那RegisterWindowMessage属于那个类呢?是那个类的函数?Top
14 楼blade_fj(小刀)回复于 2002-07-26 23:40:51 得分 10
RegisterWindowMessage是个API函数,::是作用域分辨符,表示在作用域外调用。
也就是说这里是调用了API函数Top
15 楼cywater2000(如果)回复于 2002-07-27 10:01:39 得分 5
对,这里表示它是一个API函数,其实你不加也可以Top
16 楼kevinh(每天一个太阳)回复于 2002-07-27 10:11:19 得分 5
调用win32API函数Top
17 楼ynli2002(阿男)回复于 2002-07-27 10:13:18 得分 5
API函数Top
18 楼guangde(光光)回复于 2002-07-27 11:14:28 得分 5
为了增加程序的可读性,在调用API函数时还是加上::比较好,既便于今后自己的阅读,也便于其他接手自己工作的人阅读。Top
19 楼chibaby(!小赖皮!)回复于 2002-07-28 09:47:33 得分 0
定义Top




