我现在用谷歌搜索了大约 30 分钟,但没有找到与我的问题相关的任何内容:
我使用 Visual Studio C++ 2008,它在这个头文件中为我声明了一个名为“stdafx.h”的头文件,我声明了我需要的所有东西,我希望全局变量也在那里,但是当我想使用其中一个时变量,我得到一个错误(在编译时)我的“stdafx.h”看起来像这样:
#pragma once
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
windows header here....
// C RunTime Header Files
compiler related standard headers here....
// TODO: reference additional headers your program requires here
#ifndef aaab
#include "codename.hpp"
#define aaab
#endif
// and a load of other headers (all of my project) followed here
...
...
...
在声明之后,我定义了我的全局变量,例如:
Game *game;
我想在“codename.cpp”中使用它们
这里是班级的简短介绍
#include "stdafx.h"
#define MAX_LOADSTRING 100
other class related stuff here....
main function here....
void test()
{
game = new Game(); // HERE IS THE ERROR
}