c++里这个符号::都有什么含义啊?

blooney 2009-02-22 08:00:57
百度上搜的时候都把这个::给忽略掉了
都哪里能用到呢?
比如pachage的里边的class或者Enum什么的,谁能具体讲讲啊,着急用这个呢,谢谢了
...全文
298 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
蜥蜴枪王 2009-02-23
  • 打赏
  • 举报
回复
UP 是不是也可以叫做范围解释运算符啊?好象记得可以
sincor 2009-02-23
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 dongyanwei1985 的回复:]
引用 2 楼 waizqfor 的回复:
引用楼主 blooney 的帖子:
百度上搜的时候都把这个::给忽略掉了
都哪里能用到呢?
比如pachage的里边的class或者Enum什么的,谁能具体讲讲啊,着急用这个呢,谢谢了

::域操作符啊 转个资料 LZ看看吧
::操作符有三种

第一种是全局域操作符,写法:

::token

它指示编译器的全局范围内查找后面的符号(函数、类、变量等)

第二种是域操作系…
[/Quote]
dongyanwei1985 2009-02-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 waizqfor 的回复:]
引用楼主 blooney 的帖子:
百度上搜的时候都把这个::给忽略掉了
都哪里能用到呢?
比如pachage的里边的class或者Enum什么的,谁能具体讲讲啊,着急用这个呢,谢谢了

::域操作符啊 转个资料 LZ看看吧
::操作符有三种

第一种是全局域操作符,写法:

::token

它指示编译器的全局范围内查找后面的符号(函数、类、变量等)

第二种是域操作系,写法:

token::m…
[/Quote]
很详细的解释了....
ForestDB 2009-02-23
  • 打赏
  • 举报
回复
:: scope operator
::global_variable
Class::Class_Members
Namespace::identifiers
bfhtian 2009-02-23
  • 打赏
  • 举报
回复
up
redoffice 2009-02-23
  • 打赏
  • 举报
回复
同2楼
taodm 2009-02-23
  • 打赏
  • 举报
回复
买本C++ Primer,书后索引表里一查,你基本上99%的问题都可以解决了。
Learn-anything 2009-02-23
  • 打赏
  • 举报
回复
lg
ysysbaobei 2009-02-23
  • 打赏
  • 举报
回复
xmrforever 2009-02-22
  • 打赏
  • 举报
回复
学习了
vision比心 2009-02-22
  • 打赏
  • 举报
回复
楼上的真精辟!好!
yangch_nhcmo 2009-02-22
  • 打赏
  • 举报
回复
域操作符,表示在::的左操作数中查找右操作数
比如:
ClassA::put();//表示调用ClassA中的put()函数.
ypb362148418 2009-02-22
  • 打赏
  • 举报
回复
域作用符,表示属于哪一个域的
xuruichen 2009-02-22
  • 打赏
  • 举报
回复
全局操作符,如果::前面有东西,就是域操作符
表示右操作数可以在左操作数的范围内找到。
heroxx2011 2009-02-22
  • 打赏
  • 举报
回复
感谢2楼!学习了。
thesecretblue 2009-02-22
  • 打赏
  • 举报
回复
同二楼!!!
  • 打赏
  • 举报
回复
基本就是域和空间操作符号,如果前面缺省则认为是全局域,也就是全局变量.
2楼很清楚了.
waizqfor 2009-02-22
  • 打赏
  • 举报
回复
[Quote=引用楼主 blooney 的帖子:]
百度上搜的时候都把这个::给忽略掉了
都哪里能用到呢?
比如pachage的里边的class或者Enum什么的,谁能具体讲讲啊,着急用这个呢,谢谢了
[/Quote]
::域操作符啊 转个资料 LZ看看吧
::操作符有三种

第一种是全局域操作符,写法:

::token

它指示编译器的全局范围内查找后面的符号(函数、类、变量等)

第二种是域操作系,写法:

token::member

它指示编译器在token的域内查找member的符号

第三种是名空间操作符,与第二种类似,具体参见名空间用法。

附MSDN中对该运算符的解释

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


Remarks
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
This example 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.

Copy Code
// expre_ScopeResolutionOperator.cpp
// compile with: /EHsc
// Demonstrate scope resolution operator
#include <iostream>

using namespace std;

int amount = 123; // A global variable

int main() {
int amount = 456; // A local variable
cout << ::amount << endl // Print the global variable
<< amount << endl; // Print the local variable
}
yuzl32 2009-02-22
  • 打赏
  • 举报
回复
全局限定符

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧