020
03.06.2007, 20:32 Uhr
FunnyDingo
|
Leider auch nicht das richtige :-(
Code: |
threads/thread.cpp: In static member function 'static void* class_thread::start(void*)': threads/thread.cpp:65: error: cannot dynamic_cast 'obj' (of type 'void*') to type 'class class_thread*' (source is not a pointer to class)
|
Hier mal der Code der gesamten class_thread (inkl. des letzten Vorschlags):
C++: |
#include <iostream> #include <pthread.h> #include "thread.h" #include "../error/error.h"
class_thread::class_thread() { std::cout << "class_thread::class_thread()" << std::endl; }
class_thread::~class_thread() { std::cout << "class_thread::~class_thread()" << std::endl; }
void class_thread::create() { std::cout << "Try to create thread" << std::endl; if (pthread_create(&m_handle, NULL, start, this) != 0) THROWEXCEPTION("Can't create thread!");
if (pthread_cond_init(&m_condition, NULL) != 0) THROWEXCEPTION("Can't create thread!");
if (pthread_mutex_init(&m_mutex, NULL) != 0) THROWEXCEPTION("Can't create thread!");
std::cout << "Thread created" << std::endl; }
void class_thread::wait() { pthread_join(m_handle, NULL); }
void *class_thread::start(void *obj) { class_thread *tmp = dynamic_cast<class_thread*>(obj); if(tmp != NULL) tmp->run(); else THROWEXCEPTION("Can't run thread"); return NULL; }
void class_thread::run() { }
|
-- "Der Computer ist die logische Weiterentwicklung des Menschen: Intelligenz ohne Moral." (John James Osborne)
Meine Website: http://www.funnydingo.de |