Calling an async function inside a class

  asynchronous, c++

I have this class with a few methods. One of them needs to compute and render something over a wide range of data (coordinates). To make the program run faster and smoother, I thought of using async methods. I created a private function that does the computation and rendering.

My class:

#include <future>

class MyClass {
public:

    // there's a constructor with all the class' variable-declarations and such that I will omit here

    void draw() {
        for(int i(0); i < width; ++i) {
            for(int j(0); j < width; ++j) {
                std::async(compute_and_render, i, j);
            }
        }
    }
private:
    void compute_and_render(int x, int y) {
        // does some computations and rendering
    }
}

My compiler (MinGW) says error: reference to non-static member function must be called. I also tried passing the function to async as a pointer without much success.

Source: Windows Questions C++

LEAVE A COMMENT