andreyvul wrote:
g++ says a reinterpret cast from void* is disallowed; however, all I'm
trying to do is de-capsulate a void* argument that holds the pointer
to a class (and static_cast forces cast constructor)
any solutions?
Use 'static_cast'. That's what it's for (among some other things).
also this pops up: 43: error: expected unqualified-id before 'return'
It would seem your 'return' is outside of any function.
code:
includes: stdio.h, stdlib.h, time.h, pthread.h
struct:
template <typename T> struct mergesort_thread {
T* start;
T* end;
mergesort_thread(T* _start, T* _end) { start = _start; end = _end; }
static void *invoke(void *_this) {
pthread_t threads[2];
mergesort_thread<T> *child1, *child2;
T *mid, *shift, t;
T* start = (reinterpret_cast< mergesort_thread<T> >(_this))->start;
T* end = (reinterpret_cast< mergesort_thread<T> >(_this))->end;
if (start >= end) return NULL; //recursed deep enough (1 element)
//recursively sort halves of the list
mid = (T*)(start + ((end - start) >> 1));
child1 = new mergesort_thread<T>(start, mid);
pthread_create(&threads[0], NULL, mergesort_thread<T>::invoke, (void
*)child1);
child2 = new mergesort_thread<T>(mid + 1, end);
pthread_create(&threads[1], NULL, mergesort_thread<T>::invoke, (void
*)child2);
delete child1;
delete child2;
pthread_join(threads[0], NULL);
pthread_join(threads[1], NULL);
for (;(start <= mid) && (mid + 1 <= end); start++) {
if (*start < *(mid + 1)) //sorted (current element belongs in 1st
half)
continue;
else { /* true inplace merge requires insersion-sort-like
* methods because a value from the second half is inserted to
* the current element */
//copy the first element in the second half to t
t = *(mid + 1);
//shift first half to the right
for (shift = mid; shift >= start; shift--)
*(shift + 1) = *shift;
//copy t to start
*start = t;
mid++;
}
}
}
43: return NULL;
};
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
referencing.