| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 653 人关注过本帖
标题:关于线程函数怎么用自定义头文件的问题 求大神帮助~!! 线程函数里用的是g ...
取消只看楼主 加入收藏
w716169470
Rank: 2
等 级:论坛游民
帖 子:51
专家分:25
注 册:2013-4-18
结帖率:61.54%
收藏
已结贴  问题点数:20 回复次数:2 
关于线程函数怎么用自定义头文件的问题 求大神帮助~!! 线程函数里用的是global.h里面的东西但是这段代码有警告这是什么原因?
#include <iostream>
using namespace std;
#include "draw.h"
#include "global.h"
#include "move.h"
#include "stdlib.h"
#include "stdio.h"
#include "conio.h"
#include "windows.h"
//#include <dos.h>
   
DWORD WINAPI Fun1Proc(LPVOID lpParameter);

void main()
{
    //char k;

    Move a;
   
    while(1)
    {
        a.move();   
        HANDLE hThread1 = NULL;
        hThread1 = CreateThread(NULL, 0, Fun1Proc, NULL, 0, NULL);

        a.move();   
        _sleep(1000);
    }

}

DWORD WINAPI Fun1Proc(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);
    }
}
搜索更多相关主题的帖子: include sleep 
2013-12-18 13:53
w716169470
Rank: 2
等 级:论坛游民
帖 子:51
专家分:25
注 册:2013-4-18
收藏
得分:0 
回复 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)
2013-12-19 13:47
w716169470
Rank: 2
等 级:论坛游民
帖 子:51
专家分:25
注 册:2013-4-18
收藏
得分:0 
回复 3楼 w716169470
GO Go 是在Map类里定义的 Move类继承了Map类 并且在实现类的时候对成员进行了初始化。

#ifndef DRAW_H
#define DRAW_H

#include "global.h"
#include "draw.h"

class Map
{
protected:
    char draw[KUAN][CHANG];
    char mubiao[108];
    char ban[8];
    GO Go;
public:
    Map();

};

#endif

-------------------------------------------------------------------
2013-12-19 15:14
快速回复:关于线程函数怎么用自定义头文件的问题 求大神帮助~!! 线程函数里用 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017265 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved