mercredi 9 décembre 2020

Why is std::function

Initializing a Class as shown below throws

Clang: error: implicit instantiation of undefined template 'std::function<void(int, ...)>'

GCC: error: invalid use of incomplete type ‘std::deque, std::allocator > >::value_type {aka class std::function}’

Why does this happen and what is the legal solution to passing in variadic arguments into std::function ?

#include <functional>
#include <queue>

using namespace std;

template <typename F>
class Square{
   std::queue<F> child;
};

int main(){
    Square<std::function<void(int...)>> sq;
    return 0;
}

While Why can't std::function bind to C-style variadic functions? does partially answer, it does not answer why the compiler is unable to pass down Variadic Functions within the class.

Aucun commentaire:

Enregistrer un commentaire