Cannot cast from void pointer: returns always error C2440

Hello everybody,

I having a problem which I'm not able to resovle. I try to dereference a void pointer but I always get a C2440 error. It says: 'static_cast':void* cannot be converted in wqueue<T>. I tried different cast ways but I always get the same error. Any ideas? As far as I found out I should get the error if I try to dereference without cast but in my case I cast before and still get that error.

Any ideas? Thank you for your help.

1
2
3
4
5
void *srumbler (void *arg)   
{
 wqueue<workclas*> m_queue=  static_cast<wqueue<workclass*>>(arg);
return NULL;
}


The according type wqueue in the header file:

1
2
3
4
5
6
7
8
9
10
11
12
template <typename T> class wqueue
{
    list<T> m_queue;
    pthread_mutex_t m_mutex;
    pthread_cond_t m_condv;

  public:
    wqueue() {
        pthread_mutex_init(&m_mutex, NULL);
        pthread_cond_init(&m_condv, NULL);
    }
...
Maybe try casting it to a pointer to an object rather than to an object.
arg is a pointer, whereas wqueue<workclass*> is not a pointer type. Therefore, you can't static_cast arg to wqueue<workclass*>.

Instead, you have to cast arg to wqueue<workclass*>* (ie a pointer to a wqueue object).
Thank you so much. This did the job:

wqueue<Soundfile*>* m_queue= static_cast<wqueue<Soundfile*>*>(arg);

Have a good day alltogether
Topic archived. No new replies allowed.