回复 2楼 yuccn
恩恩,我发的是一段测试代码,我想看看线程里能不能用global.h里面的东西,因为我把线程函数写在了一个类的构造函数里用不了global.h里面的东西。其实我想问线程里面是否可以用global.h自定义头文件的东西?如果用的话我这样为什么会有错误?
#include <iostream>
using namespace std;
#include "global.h"
#include "draw.h"
#include "move.h"
#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
#include <windows.h>
DWORD WINAPI FunProc(LPVOID lpParameter);
Move::Move()
{
if(draw[Go.qiu_x + Go.x][Go.qiu_y + Go.y] == KONG)
{
Go.qiu_x += Go.x;
Go.qiu_y += Go.y;
draw[Go.qiu_x][Go.qiu_y] = QIU;
draw[Go.qiu_x - Go.x][Go.qiu_y - Go.y] = KONG;
}
HANDLE hThread = NULL;
hThread = CreateThread(NULL, 0, FunProc, NULL, 0, NULL);
}
DWORD WINAPI FunProc(LPVOID lpParameter)
{
while(1)
{
if(draw[Go.qiu_x + Go.x][Go.qiu_y + Go.y] == KONG)
{
Go.qiu_x += Go.x;
Go.qiu_y += Go.y;
draw[Go.qiu_x][Go.qiu_y] = QIU;
draw[Go.qiu_x - Go.x][Go.qiu_y - Go.y] = KONG;
}
Sleep(1000);
}
}
--------------------------------------------------------------------------------
#ifndef GLOBAL_H
//global里面写的
#define GLOBAL_H
#define QIANG
'1'
//障碍物部分
#define BAN
'2'
#define QIU
'3'
#define KONG
'4'
#define MUBIAO
'5'
#define CHANG
20
#define KUAN
22
typedef struct _GO
{
int x;
int y;
int qiu_x;
int qiu_y;
int ban_x;
int ban_y;
}GO;
//
Go.qiu_x = 19;
//
Go.qiu_y = 10;
//
Go.ban_x = 20;
//
Go.ban_y = 6;
#endif
------------------------------------------------------------------------
#ifndef MOVE_H
//
Move头文件
#define MOVE_H
class Move:protected Map
{
public:
Move();
void move();
//
DWORD WINAPI FunProc(LPVOID lpParameter);
};
#endif
-----------------------------------------------------------
E:\新建文件夹\打箱子\Q_Move.cpp(31) : error C2065: 'draw' : undeclared identifier
//警告部分
E:\新建文件夹\打箱子\Q_Move.cpp(31) : error C2065: 'Go' : undeclared identifier
E:\新建文件夹\打箱子\Q_Move.cpp(31) : error C2228: left of '.qiu_x' must have class/struct/union type
E:\新建文件夹\打箱子\Q_Move.cpp(31) : error C2228: left of '.x' must have class/struct/union type
E:\新建文件夹\打箱子\Q_Move.cpp(31) : error C2228: left of '.qiu_y' must have class/struct/union type
E:\新建文件夹\打箱子\Q_Move.cpp(31) : error C2228: left of '.y' must have class/struct/union type
E:\新建文件夹\打箱子\Q_Move.cpp(33) : error C2228: left of '.qiu_x' must have class/struct/union type
E:\新建文件夹\打箱子\Q_Move.cpp(33) : error C2228: left of '.x' must have class/struct/union type
E:\新建文件夹\打箱子\Q_Move.cpp(34) : error C2228: left of '.qiu_y' must have class/struct/union type
E:\新建文件夹\打箱子\Q_Move.cpp(34) : error C2228: left of '.y' must have class/struct/union type
E:\新建文件夹\打箱子\Q_Move.cpp(35) : error C2228: left of '.qiu_x' must have class/struct/union type
E:\新建文件夹\打箱子\Q_Move.cpp(35) : error C2228: left of '.qiu_y' must have class/struct/union type
E:\新建文件夹\打箱子\Q_Move.cpp(36) : error C2228: left of '.qiu_x' must have class/struct/union type
E:\新建文件夹\打箱子\Q_Move.cpp(36) : error C2228: left of '.x' must have class/struct/union type
E:\新建文件夹\打箱子\Q_Move.cpp(36) : error C2228: left of '.qiu_y' must have class/struct/union type
E:\新建文件夹\打箱子\Q_Move.cpp(36) : error C2228: left of '.y' must have class/struct/union type
Error executing cl.exe.
打箱子.exe - 16 error(s), 0 warning(s)