Compilation Error in using async with templates

I am trying to create a new thread with a recursive function call to the function itself:
    std::async(std::launch::async, &CQSort<typename T>::qSort1, arr, start, p-1);
p is defined as an integer in a local variable.


The function qSort1 is implemented as

template <typename T>
void CQSort<typename T>::qSort1(T &arr, int start, int end)
{...}

I am getting a compilation error in the async call. 
Error C2672 'std::async': no matching overloaded function found

This compiles and runs. I'm not sure it's entirely correct, though.
Note in particular that you need to pass a pointer to an object after the member-function pointer, since a member function needs an object to be called from.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <future>

template <typename T>
struct CQSort {
    void qSort1(T* arr, int start, int p);
};

template <typename T>
void CQSort<T>::qSort1(T* arr, int start, int p) {
    std::cout << arr[start] << ' ' << p << '\n';
}

template <typename T>
void f(T* arr, int start, int p) {
    CQSort<T> cqs;
    std::async(std::launch::async,
               &CQSort<T>::qSort1, &cqs, arr, start, p - 1);
}

int main() {
    int arr[10] {42}, start = 0, p = 4;
    f(arr, start, p);
}

Topic archived. No new replies allowed.