Ravey Alexandre | 13 Oct 01:45

[Function] Encapsulated inside a class, won't initialize.


Hi there,

I'm using boost::function defined private inside a class and then assign a function comming from another boost::function. But it don't work.

A little code may help understand my pretty bad explanation.
#######
  class C
  {
    public:
      void Bind(boost::function<void()> f);
    private:
      boost::function<void()> func;
  };

  void C::Bind(boost::function<void()
> f)
  {
    func = f;  //Compile, but raise an access violation.
  }
#######

The problem seems obvious to me, func si not initialized correctly and swap() fail.

But I can't figure out how to make this work.

Thanks for your help.
_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Jeff Flinn | 13 Oct 15:20
Favicon

Re: [Function] Encapsulated inside a class, won't initialize.

Ravey Alexandre wrote:
> 
> Hi there,
> 
> I'm using boost::function defined private inside a class and then assign 
> a function comming from another boost::function. But it don't work.
> 
> A little code may help understand my pretty bad explanation.
> #######
>   class C
>   {
>     public:
>       void Bind(boost::function<void()> f);
>     private:
>       boost::function<void()> func;
>   };
> 
>   void C::Bind(boost::function<void()
>  > f)
>   {
>     func = f;  //Compile, but raise an access violation.
>   }
> #######
> 
> The problem seems obvious to me, func si not initialized correctly and 
> swap() fail.
> 
> But I can't figure out how to make this work.

Can you provide a minimally complete compilable example that exhibits 
the problem. I think the problem lies in the code that you don't show. 
For example your instance of Class C may not be properly constructed, or 
the function f has bound arguments that do not copy/assign properly.

Jeff

Gmane