pwang
pwang

Reputation: 488

:: without a namespace

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?

Upvotes: 17

Views: 6322

Answers (3)

Sarfaraz Nawaz
Sarfaraz Nawaz

Reputation: 361402

:: 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

Upvotes: 23

Alok Save
Alok Save

Reputation: 206526

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

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

means refer to CGContextRef in the Global Namespace.

Upvotes: 5

Pepe
Pepe

Reputation: 6480

The :: refers to the global namespace.

Upvotes: 8

Related Questions