本文介绍了前置双冒号“::"是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个必须修改的类中发现了这行代码:

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

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

而且我不知道类名前面的双冒号到底是什么意思.没有它,我会读到:tmpCo 的声明作为指向 Configuration 类的对象的指针......但是前置的双冒号让我感到困惑.

and I don't know what exactly means the double colon prepended to the class name. Without that I would read: declaration of tmpCo as a pointer to an object of the class Configuration... but the prepended double colon confuses me.

我还发现:

typedef ::config::set ConfigSet;

推荐答案

这可确保从全局命名空间开始解析,而不是从您当前所在的命名空间开始.例如,如果您有两个名为 配置如下:

This ensures that resolution occurs from the global namespace, instead of starting at the namespace you're currently in. For instance, if you had two different classes called Configuration as such:

class Configuration; // class 1, in global namespace
namespace MyApp
{
    class Configuration; // class 2, different from class 1
    function blah()
    {
        // resolves to MyApp::Configuration, class 2
        Configuration::doStuff(...)
        // resolves to top-level Configuration, class 1
        ::Configuration::doStuff(...)
    }
}

基本上,它允许您遍历全局命名空间,因为您的名称可能会被另一个命名空间内的新定义破坏,在本例中为 MyApp.

Basically, it allows you to traverse up to the global namespace since your name might get clobbered by a new definition inside another namespace, in this case MyApp.

这篇关于前置双冒号“::"是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 02:00