Boost logo

Boost Users :

Subject: [Boost-users] boost bind example does not compile with member template function on gcc 4.0
From: James Pritts (jbpritts_at_[hidden])
Date: 2009-07-14 14:37:14


Unfortunately I cannot grok boost::bind error, but this code seems really
simple. If I change the code so that an int is passed to async_discovery,
the program compiles. The problem seems to be centered around passing a
boost::bind as a template argument. Any help would be appreciated.

Here is the code...

#include <boost/bind.hpp>

class antix_discovery_service {
public:
  template <typename Handler>
  void start_async_discovery(Handler handler)
  {
  }

  /// Asynchronously resolve a query to a list of entries.
  template <typename Handler>
  void async_discovery(Handler handler)
  {
    boost::bind(&antix_discovery_service::template
start_async_discovery<Handler>,
        this, handler)();
  }

private:
  int ttt;
};

class test
{
public:
  void do_it()
  {
  }
};

int main()
{
  antix_discovery_service ads;
  test t;
  ads.async_discovery(boost::bind<void>(&test::do_it, t));
  return 0;
}

and here is the error...

main.cpp: In function 'int main()':
main.cpp:33: warning: unused variable 'jjj'
../vendor/boost/boost/bind/bind.hpp: In member function 'void
boost::_bi::list2<A1, A2>::operator()(boost::_bi::type<void>, F&, A&, int)
[with F = boost::_mfi::mf1<void, antix_discovery_service,
boost::_bi::bind_t<void, boost::_mfi::mf0<void, test>,
boost::_bi::list1<boost::_bi::value<test> > > >, A = boost::_bi::list0, A1 =
boost::_bi::value<antix_discovery_service*>, A2 = boost::_bi::bind_t<void,
boost::_mfi::mf0<void, test>, boost::_bi::list1<boost::_bi::value<test> >
>]':
../vendor/boost/boost/bind/bind_template.hpp:20: instantiated from
'typename boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F,
L>::operator()() [with R = void, F = boost::_mfi::mf1<void,
antix_discovery_service, boost::_bi::bind_t<void, boost::_mfi::mf0<void,
test>, boost::_bi::list1<boost::_bi::value<test> > > >, L =
boost::_bi::list2<boost::_bi::value<antix_discovery_service*>,
boost::_bi::bind_t<void, boost::_mfi::mf0<void, test>,
boost::_bi::list1<boost::_bi::value<test> > > >]'
main.cpp:14: instantiated from 'void
antix_discovery_service::async_discovery(Handler) [with Handler =
boost::_bi::bind_t<void, boost::_mfi::mf0<void, test>,
boost::_bi::list1<boost::_bi::value<test> > >]'
main.cpp:35: instantiated from here
../vendor/boost/boost/bind/bind.hpp:306: error: invalid use of void
expression
...failed gcc.compile.c++ ..\.bin\test_bind\gcc-4.0\debug\main.o...
...skipped <p..\.bin\test_bind\gcc-4.0\debug>test_bind.avc for lack of
<p..\.bin\test_bind\gcc-4.0\debug>main.o...
...skipped <p..\.bin\test_bind\gcc-4.0\debug>test_bind.ix86-win32.elf for
lack of <p..\.bin\test_bind\gcc-4.0\debug>test_bind.avc...
...skipped <pinstall>test_bind.ix86-win32.elf for lack of
<p..\.bin\test_bind\gcc-4.0\debug>test_bind.ix86-win32.elf...
...failed updating 1 target...
...skipped 3 targets...

Compilation exited abnormally with code 1 at Tue Jul 14 14:27:58

-Jimmy.



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