c语言creat函数,C语言 如何调用 pthread_create 里函数的参数?

1.使用pthread,调用的函数的参数是class中的,该如何处理?

2.代码如下

#include

#include

#include

#include

#include

#include

#define KEY_UP 'w'

#define KEY_DOWN 's'

#define KEY_LEFT 'a'

#define KEY_RIGHT 'd'

#define FIRE 'j'

class Player {

private:

int positionX;

int positionY;

int positionA;

int positionB;

public:

void SetPositionX(int x) { positionX = x; }

void SetPositionY(int y) { positionY = y; }

int GetPositionX() { return positionX; }

int GetPositionY() { return positionY; }

int m, n; //子弹坐标

};

void SetPosition(int x, int y)

{

COORD coord;

coord.X = 2 * x;

coord.Y = y;

HANDLE handle;

handle = GetStdHandle(STD_OUTPUT_HANDLE);

SetConsoleCursorPosition(handle,coord);

HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);

CONSOLE_CURSOR_INFO cursor_info = {1, 0};

SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);

}

void *Controller(Player &pl)

{

int direction;

if (_kbhit()) { //_kbhit()为true当且仅当用户按下键盘

switch (_getch()) { //_getch()返回用户按下的那个按键,注意使用小写

//根据玩家的输入进行移动

case KEY_UP:

if (pl.GetPositionY() == 1 ) {

break;

}

else {

SetPosition(pl.GetPositionX(), pl.GetPositionY());

printf(" ");

pl.SetPositionY(pl.GetPositionY() - 1); //

SetPosition(pl.GetPositionX(), pl.GetPositionY()); //改变光标位置到改变后的位置

printf("○"); //进行玩家的移动

direction = 1;

}

break;

case KEY_DOWN:

if (pl.GetPositionY() == 21 ) {

break;

}

else {

SetPosition(pl.GetPositionX(), pl.GetPositionY());

printf(" ");

pl.SetPositionY(pl.GetPositionY() + 1);

SetPosition(pl.GetPositionX(), pl.GetPositionY());

printf("○");

direction = 2;

}

break;

case KEY_LEFT:

if (pl.GetPositionX() == 1 ) {

break;

}

else {

SetPosition(pl.GetPositionX(), pl.GetPositionY());

printf(" ");

pl.SetPositionX(pl.GetPositionX() - 1);

SetPosition(pl.GetPositionX(), pl.GetPositionY());

printf("○");

direction = 3;

}

break;

case KEY_RIGHT:

if (pl.GetPositionX() == 37 ) {

break;

}

else {

SetPosition(pl.GetPositionX(), pl.GetPositionY());

printf(" ");

pl.SetPositionX(pl.GetPositionX() + 1);

SetPosition(pl.GetPositionX(), pl.GetPositionY());

printf("○");

direction = 4;

}

break;

default:break;

}

}

}

int main()

{

int pth1, loop01;

pthread_t threads;

Player player, enemy; //声明一个自定义的玩家类型变量

srand((unsigned)time(NULL));

player.SetPositionX(rand()%30+2);

player.SetPositionY(rand()%15+2); //设置初始坐标

enemy.SetPositionX(rand()%30+2);

enemy.SetPositionY(rand()%15+2);

while (1) //游戏循环

{ //问题在此

pth1 = pthread_create(&threads, NULL, Controller, (void*)Player &player);

} //参数该如何调用?

system("pause");

return 0;

}

3.报错如下

E:\Workspace\C\Game test\problem.cpp: In function 'int main()':

E:\Workspace\C\Game test\problem.cpp:119:67: error: expected primary-expression

before '&' token

pth1 = pthread_create(&threads, NULL, Controller, (void*)Player &player);

^

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值