Boost logo

Boost Users :

From: JOAQUIN LOPEZ MU?Z (joaquin_at_[hidden])
Date: 2006-11-29 18:10:11


Hello Noah,

----- Mensaje original -----
De: Noah Roberts <roberts.noah_at_[hidden]>
Fecha: Miércoles, Noviembre 29, 2006 11:49 pm
Asunto: [Boost-users] more lambda issues
Para: boost-users_at_[hidden]

> I'm kind of loosing faith that this list ever responds to questions
> but here goes anyway.
>
> I've narrowed a problem down to this:
>
[...]
> std::cerr << "Value: " <<
> (l::bind(&test_b::f, l::_1))(td) << "\n";
[...]
> Compiler result: cannot instantiate abstract class test_b.
 
I haven't been following your investigations into the Boost
Lambda Library so excuse me if he following is not relevant:
your example can be made to work by using boost::reference_wrappers:

#include <iostream>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/ref.hpp>

struct test_b
{
  test_b() { std::cerr << "test_b::test_b()\n"; }
  test_b(test_b const&) { std::cerr << "test_b::test_b(test_b const&)
\n"; }
  virtual int f() = 0; //{ return 5; }

};

struct test_d : test_b
{
  test_d() : test_b() { std::cerr << "test_d::test_d()\n"; }
  test_d(test_d const& d) : test_b(d) { std::cerr <<
"test_d::test_d(test_d const&)\n"; }
  int f() { return 5; }
};

int main(void)
{
  namespace l = boost::lambda;

  test_d tdo;
  test_b & td = tdo;

  std::cerr << "Value: " <<
    (l::bind(&test_b::f, l::_1))(boost::ref(td)) << "\n";

  int x; std::cin >> x;
}

Another acceptable syntax that does not use reference wrappers
is the following:

  std::cerr << "Value: " <<
    (&l::_1->*&test_b::f)(td)() << "\n";

HTH,

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net