G
Guenther Sohler
Hallo,
I have written a very small testcase to try threads within classes
My code is following:
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
class test
{
public:
test(void);
friend void *test::work_func(void *);
~test();
};
test::test(void)
{
pthread_t t;
printf("Constructor\n");
if(pthread_create(&t,NULL,work_func,NULL))
printf("No Thread created!\n");
}
void *test::work_func(void *)
{
while(1) printf("Working\n");
return NULL;
}
test::~test()
{
printf("Destructor\n");
}
int main(void)
{
test x;
sleep(1);
}
g++ -o testcase testcase.cpp -lpthread -Wall
testcase.cpp:9: warning: member functions are implicitly friends of their class
My goal is to get rid of the warning. And I want to keep the function
'work_func' within the class 'test'. How can I change the code to get it
clean ?
rds Guenther
I have written a very small testcase to try threads within classes
My code is following:
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
class test
{
public:
test(void);
friend void *test::work_func(void *);
~test();
};
test::test(void)
{
pthread_t t;
printf("Constructor\n");
if(pthread_create(&t,NULL,work_func,NULL))
printf("No Thread created!\n");
}
void *test::work_func(void *)
{
while(1) printf("Working\n");
return NULL;
}
test::~test()
{
printf("Destructor\n");
}
int main(void)
{
test x;
sleep(1);
}
g++ -o testcase testcase.cpp -lpthread -Wall
testcase.cpp:9: warning: member functions are implicitly friends of their class
My goal is to get rid of the warning. And I want to keep the function
'work_func' within the class 'test'. How can I change the code to get it
clean ?
rds Guenther