Use of namespace in C++?
本问题已经有最佳答案,请猛点这里访问。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include"d3dApp.h" #include <WindowsX.h> #include <sstream> namespace { // This is just used to forward Windows messages from a global window // procedure to our member function window procedure because we cannot // assign a member function to WNDCLASS::lpfnWndProc. D3DApp* gd3dApp = 0; } LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { // Forward hwnd on because we can get messages (e.g., WM_CREATE) // before CreateWindow returns, and thus before mhMainWnd is valid. return gd3dApp->MsgProc(hwnd, msg, wParam, lParam); } |
我对C++中命名空间的使用感到好奇。我开始阅读关于名称空间的文档,我看到了很多例子调用名称空间的名称,比如"名称空间优先",但是在像这样的名称空间声明之后,没有一个名称空间没有任何内容。
这是一个匿名或未命名的命名空间。名称空间中的项(本例中只有
注意:这不会阻止外部连杆。请看这里:http://msdn.microsoft.com/en-us/library/yct4x9k5(v=vs.80).aspx。
Although entities in an unnamed namespace might have external linkage, they are effectively qualified by a name unique to their translation unit and therefore can never be seen from any other translation unit.
这项技术略优于