我正在使用 Visual Studio 2012 Professional 制作我的第一个 windows/directx 程序。在我的程序的顶部,我有这个:
3: #define SCREEN_HEIGHT 500;
4: #define SCREEN_WIDTH 400;
在我决定使用常量之前,它工作得非常好:
49: //set size but not coordinates. we'll do that when we create the window
50: RECT clientArea = {0, 0, 500, 400};
51: //x-coordinates, y-coordinates, height, width
52:
53: //Makes the previous struct have the values for the client area not the window
54: AdjustWindowRect(&clientArea, WS_OVERLAPPEDWINDOW, FALSE);
55: //address of previously defined RECT, window style, do we have a menu?
56:
57: //create the window and store the handle
58: windowHandle = CreateWindowEx(NULL,
59: "WindowClass1", //name of window class
60: "My First Windowed Program", //title of window
61: WS_OVERLAPPEDWINDOW, //window style
62: 400, //x-position
63: 200, //y-position
64: clientArea.right - clientArea.left, //width
65: clientArea.bottom - clientArea.top, //height
66: NULL, //No parent
67: NULL, //We dont have any menu's
68: whichInstance, //instance handle
69: NULL); //we only have one window
70:
71: //display the window
72: ShowWindow(windowHandle, howToShowTheWindow);
73: //struct with window information, defined by windows in WinMain.
但是当我改变这一行时:
50: RECT clientArea = {0, 0, SCREEN_HEIGHT, SCREEN_WIDTH};
它给了我大约三十个不同的错误。我很确定只有前几个是相关的,其余的是因为这些代码行没有正常工作..
1>c:\users\kenneth\documents\visual studio 2012\projects\my first directx program\my first directx program\my first dirextx program.cpp(50): error C2143: syntax error : missing '}' before ';'
1>c:\users\kenneth\documents\visual studio 2012\projects\my first directx program\my first directx program\my first dirextx program.cpp(50): error C2143: syntax error : missing ';' before ','
1>c:\users\kenneth\documents\visual studio 2012\projects\my first directx program\my first directx program\my first dirextx program.cpp(54): error C2065: 'clientArea' : undeclared identifier
1>c:\users\kenneth\documents\visual studio 2012\projects\my first directx program\my first directx program\my first dirextx program.cpp(54): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\kenneth\documents\visual studio 2012\projects\my first directx program\my first directx program\my first dirextx program.cpp(54): error C2365: 'AdjustWindowRect' : redefinition; previous definition was 'function'
如果我正确理解定义的常量,预处理器会在任何编译完成之前简单地将它们换成它们的值,所以这非常令人困惑。