- 论坛徽章:
- 0
|
代码先上:
stdafx.h
-------------------------------------stdafx.h----------
#include <iostream>
#include <string>
#include <pthread.h>
#include <signal.h>
#include <cstdlib>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <map>
using namespace std;
class teststatic {
public:
int a;
int b;
teststatic(){}
~teststatic(){}
void *fun(void *pvoid);
create();
};
void *teststatic::fun(void *pvoid){
int *p = (int *)pvoid;
b++;
}
teststatic::create(){
pthread_t pid;
pthread_create(&pid, NULL,fun,&a);
}
-----------------------------stdafx.h-------------
-----test.cpp-------------------------
#include "stdafx.h"
int main(){
teststatic ts;
ts.create();
sleep(3);
cout<<ts.b<<endl;
return 0;
}
---------------test.cpp-----------
运行结果:
error: argument of type `void*(teststatic: (void*)' does not match `void*(*)(void*)'
----------------------------------
为什么啊??糊涂了?难道不能用b这个变量?b在内部也不是共享??
难道一定要用pvoid传进去?不能共享b这个变量吗?我变量多的时候,怎么办啊?一次只能传一个pvid的,难道弄个结构体或者类什么的吗? |
|