I have a linkage error with the following example:
In a file named a.h:
namespace n {
class A {
...
public:
template<class Function, class... Args>
void a_member(Function &&f, Args &&...args);
private:
std::thread *t_;
};
}
In A.cpp:
#include "A.h"
template<class Function, class... Args>
void n::A::a_member(Function &&f, Args &&...args) {
this->t_ = new std::thread(std::forward<Function>(f), std::forward<Args>(args)...);
}
In a file named B.h:
#include "a.h"
#include "c.h" /* declaration of class C */
class B {
public:
void b_member1();
void b_member2(C c);
private:
A *a_;
};
In B.cpp:
#include "B.h"
void B::b_member1() {
C c;
this->a_ = new A();
this->a_->a_member(&B::b_member2, c);
}
I'd like to wrap the call to the thread callback with a member function with a parameter of class C.
EDIT:
Since the method has been moved in the header, an error still persist: the call to thread constructor seems to be incorrect (signature of function mismatch):
this->t_ = new std::thread(std::forward<Function>(f), std::forward<Args>(args)...);