cannot declare field ‘’ to be of abstract type ‘’

  asynchronous, c++

I’m trying to write asynchronous code on callbacks and stuck into this error:

error: cannot declare field ‘std::_Head_base<3, Callback, false>::_M_head_impl’ to be of abstract type ‘Callback’ 
note:   because the following virtual functions are pure within ‘Callback’
...
error: no matching function for call to ‘std::tuple<api_add(int, int, Callback&&)::<lambda(int, int, Callback&&)>, int, int, Callback>::tuple(<brace-enclosed initializer list>)} };

My abstract class:

class Callback {
public:
    virtual void OnResult(ApiResultType res) = 0;
};

Derived class:

class ApiCallBack: public Callback {
public:
    ApiCallBack() {

    };
    virtual void OnResult(ApiResultType res) {
        std::cout << "OnResult: " << res.first << "; " << res.second << std::endl;
        ...
    }
};

main():

int main() {
    // Running API operations

    ApiCallBack Callable;
    api_add(kOperationArg1, kOperationArg2, std::forward<ApiCallBack>(Callable));
    ...
}

Asynchronous function implementation:

void api_add(int arg1, int arg2, Callback &&func) {
    std::async(std::launch::async, [](int arg1, int arg2, Callback &&func) {
                func.OnResult({"API_Mul", arg1 + arg2});
               }, arg1, arg2, std::forward<Callback>(func));
}

After spending a bit of time understanding the code I wrote I suggest that the error is in the last chunk of code (async or lambda), but can’t still figure out what’s actually wrong. Please help.

Source: Windows Questions C++

LEAVE A COMMENT