0

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)...);
Eole
  • 1
  • 1
  • I'm not sure on how to solve the problem with the link you provided. – Eole Jun 15 '16 at 00:21
  • Move the implementation of `a_member` to the header file – Praetorian Jun 15 '16 at 01:05
  • Thank you, I moved the definition in the header however, I still can not compile. The problem is the call to the thread constructor (the signature doesn't match) `this->t_ = new std::thread(std::forward(f), std::forward(args)...);` – Eole Jun 15 '16 at 09:34
  • You're missing the implicit `this` argument: `this->a_->a_member(&B::b_member2, *this, c);`. – Pixelchemist Jun 15 '16 at 13:31
  • Yes, I just figured it out.. Too many hours coding... time to have a break. Thank you :) – Eole Jun 15 '16 at 16:18

0 Answers0