Namespace 'cmb1' causes C++ compilation error
When I try to compile this code:
#include <windows.h>
namespace cmb1 {
}
void main() {}
I get this:
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
a.cc
a.cc(3) : error C2059: syntax error : 'consta开发者_如何学编程nt'
a.cc(3) : error C2143: syntax error : missing ';' before '{'
a.cc(3) : error C2447: '{' : missing function header (old-style formal list?)
Ditto for cmb2
, cmb3
and cmb4
. I stopped at that point. cm4
, btw, compiles just fine.
I tried surrounding the namespace with something else:
namespace dilum {
namespace cmb4 {
}
}
But the compile still failed.
What is going on?
from windows.h:
#define cmb1 0x470
#define cmb2 0x471
#define cmb3 0x472
#define cmb4 0x473
#define cmb5 0x474
#define cmb6 0x475
#define cmb7 0x476
#define cmb8 0x477
#define cmb9 0x478
#define cmb10 0x479
#define cmb11 0x47A
#define cmb12 0x47B
#define cmb13 0x47C
#define cmb14 0x47D
#define cmb15 0x47E
#define cmb16 0x47F
cmb1
may be a macro defined in windows.h
. If the macro expands itself to an expression, the compiler sees
namespace <the_expanded_expression> {
}
The constant cmb1
is defined in <windows.h>
as follows:
#define cmb1 0x0470
If you are using Visual Studio 2010, you can hover over the red squiggly arrow under cmb1
to see the definition.
Needless to say, namespace 0x0470 { }
is not a valid namespace declaration.
精彩评论