考虑以下代码行:
::CGContextRef cgContext = cocoa::createCgBitmapContext( surface );
为什么在 :: 前面没有指定命名空间呢? 这是不是意味着它使用了你所在的类相同的命名空间?
考虑以下代码行:
::CGContextRef cgContext = cocoa::createCgBitmapContext( surface );
为什么在 :: 前面没有指定命名空间呢? 这是不是意味着它使用了你所在的类相同的命名空间?
::CGContextRef
中的::
表示全局命名空间,这意味着CGContextRef
在全局命名空间中定义。
int x = 10;
namespace test
{
int x = 100;
void f()
{
std::cout << x << std::endl; //prints 100
std::cout << ::x << std::endl; //prints 10
}
}
点击此处查看完整演示:http://www.ideone.com/LM8uo
::
在没有命名空间的情况下使用,表示它引用 全局命名空间。
::CGContextRef cgContext = cocoa::createCgBitmapContext( surface );
意思是在全局命名空间中引用 CGContextRef
。