Boost logo

Boost Users :

Subject: [Boost-users] compile errors with boost::bind
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2010-06-16 20:53:45


Hello,

I'm getting some compiler errors with boost::bind that I'm not able to figure out.

I was able to reduce it to the following minimal example:

        #include <boost/bind.hpp>

using boost::bind;

template <typename RawProc>
void AdapterProc(RawProc proc)
{
    // do other stuff, then call proc()
}

template <typename RawProc>
void f(RawProc proc)
{
    bind(&AdapterProc<RawProc>, proc)();
}

void RawProc(int x);

int main()
{
    f(bind(&RawProc, 0));
}

The compiler errors with gcc 4.4 are the following:

In file included from /usr/include/boost/bind.hpp:22,
from test.cpp:1:
/usr/include/boost/bind/bind.hpp: In member function ‘void boost::_bi::list1<
        boost::_bi::bind_t<
            void, void (*)(int), boost::_bi::list1<boost::_bi::value<int> > > >
    ::operator()(
        boost::_bi::type<void>, void (*)(
            boost::_bi::bind_t<
                void, void (*)(int), boost::_bi::list1<boost::_bi::value<
                        int>>>)&, boost::_bi::list0 &, int)’:
/usr/include/boost/bind/bind_template.hpp:20: instantiated from ‘boost::_bi
    ::result_traits<
        void, void (*)(
            boost::_bi::bind_t<
                void, void (*)(int), boost::_bi::list1<boost::_bi::value<
                        int>>>)
>::type boost::_bi::bind_t<
        void, void (*)(
            boost::_bi::bind_t<
                void, void (*)(int), boost::_bi::list1<boost::_bi::value<
                        int>>>), boost::_bi::list1<
            boost::_bi::bind_t<
                void, void (*)(int), boost::_bi::list1<boost::_bi::value<int> >
> > >::operator()()’
test.cpp:14: instantiated from ‘void f(
        boost::_bi::bind_t<
            void, void (*)(int), boost::_bi::list1<boost::_bi::value<int>>>)’
test.cpp:21: instantiated from here
/usr/include/boost/bind/bind.hpp:246: error: conversion from ‘void’ to non-
    scalar type ‘boost::_bi::bind_t<
        void, void (*)(int), boost::_bi::list1<boost::_bi::value<int>>>’
    requested

I noticed that if I modify the global RawProc to take no arguments so that I don't need
another bind() call in main() (I can just pass &RawProc to f() directly), it works fine.

Could someone explain what I'm doing wrong?

On a more general note, does anyone have some tips on how to interpret error messages
like this from boost? It seems to me that without reading through the sources and understanding
how the libraries are implemented, figuring out the cause of these errors is next to impossible...

Thanks,
Nate.
                                               
_________________________________________________________________
Game on: Challenge friends to great games on Messenger
http://go.microsoft.com/?linkid=9734387



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