我收到此错误消息,但我似乎不明白。ANSI C++ 禁止在赋值中从“void *”进行隐式转换是什么意思?. 而 Fork 函数只需要函数名和一个数字
线程::Fork(VoidFunctionPtr func, int arg)
错误信息:
../threads/threadtest.cc: In function `void ServerThread(int)':
../threads/threadtest.cc:72: ANSI C++ forbids implicit conversion from `void *' in assignment
../threads/threadtest.cc:78: implicit declaration of function `int WorkerThread(...)'
地区:
72 - 78:
nextReq = list -> Remove();
//check till the end
while (nextReq != NULL)
{
WorkerThread(&nextReq);
代码:
#include "copyright.h"
#include "system.h"
#include <stdio.h>
#include "request.h"
extern void serve(char *url);
//GLOBAL VARIABLE LIST
List *list;
//----------------------------------------------------------------------
// ThreadTest
// read file and serve urls
//----------------------------------------------------------------------
void
ClientThread(int request)
{
const int sz = 50;
char url[sz];
FILE *fp = fopen("url.txt", "r");
if (!fp)
printf(" Cannot open file url.txt!\n");
else {
int pos = 0;
char c = getc(fp);
while (c != EOF || pos == sz - 1) {
if (c == '\n') {
url[pos] = '\0';
serve(url);
pos = 0;
//Store necessary information in a Request object for each request.
Request req(url, request, 1);
Request *reqq = &req; //req points to the object
list->Append(reqq);
}
else {
url[pos++] = c;
}
c = getc(fp);
}
fclose(fp);
}
}
//----------------------------------------------------------------------
void
ServerThread(int which)
{
Request *nextReq;
//gets the first node off the list
nextReq = list -> Remove();
//check till the end
while (nextReq != NULL)
{
WorkerThread(nextReq);
}
}
//----------------------------------------------------------------------
void
WorkerThread (Request req)
{
serve(req.url);
currentThread -> Yield();
}
//----------------------------------------------------------------------
void
ThreadTest()
{
DEBUG('t', "Entering SimpleTest");
printf("THREAD TEST");
//Thread *c = new Thread("client thread");
Thread *s = new Thread("server thread");
s->Fork(ServerThread, 1);
ClientThread(0);
}