What is the meaning of prepended double colon “::”?

前端 未结 9 2076
鱼传尺愫
鱼传尺愫 2020-11-22 15:54

I found this line of a code in a class which I have to modify:

::Configuration * tmpCo = m_configurationDB;//pointer to current db

and I do

9条回答
  •  死守一世寂寞
    2020-11-22 16:11

    The :: operator is called the scope-resolution operator and does just that, it resolves scope. So, by prefixing a type-name with this, it tells your compiler to look in the global namespace for the type.

    Example:

    int count = 0;
    
    int main(void) {
      int count = 0;
      ::count = 1;  // set global count to 1
      count = 2;    // set local count to 2
      return 0;
    }
    

提交回复
热议问题