Boost logo

Boost Users :

From: jbd (evadream.mlist_at_[hidden])
Date: 2006-05-12 14:24:35


Ok, thank you responding me !

My example was just here as "proof" of what i need.

My idea is to encapsulate a boost::function of any type in a template
class, which herite from a pure virtual class FooVirtual.

My goal is to transform any function into a FooVirtual* using an
helper function.

I realize my last message was not very clear, here is a better example

#include <iostream>
#include <stdexcept>
#include <boost/bind.hpp>
#include <boost/function.hpp>

template <typename Ret, typename Arg1>
boost::function<Ret (Arg1)> mybind(Ret (*Func)(Arg1))
{
    boost::function<Ret (Arg1)> f(Func) ;
    return f ;
}

void bar() {}
void bar2(int a) {}

int main (int argc, char* argv[])
{
    try
    {
        
            boost::function < void ()> f1( boost::bind(&bar) ) ;
            boost::function < void (int) > f2( boost::bind(&bar2,_1) ) ;
            
           // doesn't work :
           // boost::function < void (int) > f2( boost::bind(&bar2) ) ;

            // this is ok
            boost::function < void (int) > f3( mybind(&bar2) ) ;
        }
    catch(std::exception& e)
    {
        std::cout << e.what() << '\n' ;
        return -1 ;
    }
    catch(...)
    {
        std::cout << "Non standard exception\n" ; return -1 ;
    }
}


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