Question

I wanted to create a function for a class method from a specific instance. As in the example, I'd like to create a function for this->x.

class A {
 public:
  void x(int p) { }
  void y() {
    function<void(int)> f = std::tr1::bind(
      &A::x,
      this,
      std::tr1::placeholders::_1);
  }
};

When I tried to compile this, I got very long error messages. One of them that might make some sense is note: no known conversion for argument 1 from ‘int’ to ‘int&’

Was it helpful?

Solution

It's best to migrate from TR1, which is an informal proposal from 2006, to C++11, which incorporated most of TR1 verbatim (meaning that a TR1 program is probably converted C++11 if you just remove the tr1::s).

Although the interfaces are mostly the same, the TR1 implementation is separate. So it's basically frozen in time, and new compiler quirks might cause it to break. Or on other platforms, they might alias TR1 features forward to "native" C++11 meaning that tr1:: classes might have differences from the actual TR1 spec.

On GCC, after removing tr1::, remove tr1/ from the headers and pass -std=c++11 on the command line.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top