mercredi 10 février 2021

Linker causes problem when compiling template c++ while passing lamda functions [duplicate]

I have a function with this signature.

template<class F, class... Args>
    auto enqueue(F f, Args &&... args)
    -> std::future<typename std::result_of<F(Args...)>::type>;

It is present in a header file along with a corresponding implemetation in a c++ file.

From another file, I call it.

pool.enqueue([](control &c, float arg){return c.move_ver(arg);}, *player_c, SPEED(key_state));

I get the following error when compiling

function 'thread_pool::enqueue<(lambda at /Users/{username}/code/C/opengl/one.cpp:75:22), 
control &, float>' is used but not defined in this translation unit, and cannot be defined in any other translation unit because its type does not have linkage

It compiles fine if the function is called from the same file where it is declared. I am prettty sure it is a linker error.

I am compiling on MacOS with apple clang.

Aucun commentaire:

Enregistrer un commentaire