开发者

:: without a namespace

开发者 https://www.devze.com 2023-03-04 23:19 出处:网络
Consider the following line of开发者_运维技巧 code: ::CGContextRef cgContext = cocoa::createCgBitmapContext( surface );

Consider the following line of开发者_运维技巧 code:

::CGContextRef cgContext = cocoa::createCgBitmapContext( surface );

How come there's no namespace specified before :: ? Does that mean it's using the same namespace as the class you're in?


:: in ::CGContextRef means global namespace, which means CGContextRef is defined in the global namespace.

int x = 10; 
namespace test
{
    int x = 100;
    void f() 
    {
         std::cout << x << std::endl;  //prints 100
         std::cout << ::x << std::endl; //prints 10
    }     
}

See complete demo here : http://www.ideone.com/LM8uo


The :: refers to the global namespace.


:: without any namespace name before it means it refers Global Namespace.

::CGContextRef cgContext = cocoa::createCgBitmapContext( surface );

means refer to CGContextRef in the Global Namespace.

0

精彩评论

暂无评论...
验证码 换一张
取 消