各位, 我问个弱一点的问题, 请给予帮助.
在写VS.net 环境下写VC++的代码时, 在系统函数和API中,有些函数是用::运算符招唤来,而有些函数不是,直接写函数名即可. 我想知道这两类函数的区别. 将::称为开域运算符,那么在未招定类名称时,它默认的是开了哪个域呢?
还请不吝指教

解决方案 »

  1.   

    未招定类名称时,就是调用当前类的成员函数,其实是调用了一个隐含的 this 指针 
    this->fun();
    或者可以这样理解,假设你当前的类为A,则
    调用A的成员函数
    fun();就为:A::fun();但要注意非静态成员函数对于每个实例化对象都是不一样的.
    很多时候你的类都是继承下来的,比如
    class CDlg : public CDialog

    ...
    }很多时候你都是在调用其基类 CDialog或者的CDialog的基类的成员函数等等.
      

  2.   

    未指定类名时, ::告诉编译器实用全局名称空间
    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
    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.