|
Boost Users : |
Subject: Re: [Boost-users] [Q] error with shared_ptr, for_each, boost::mem_fn
From: V S P (toreason_at_[hidden])
Date: 2009-02-24 21:12:03
Ok, I apologize
I misunderstood the suggestion
I made the function as non static member, but kept the input argument.
If I make myfunc to take void, then it works.
I would like to know if there any way to use static member functions
with
the for_each sematic and shared_ptr
thank you,
Vlad
On Tue, 24 Feb 2009 21:04 -0500, boost-users_at_[hidden] wrote:
> Hi, thank you for such a quick reply
>
> I have tried the member function, getting different type of error now
> class B;
> struct A : public enable_shared_from_this<A>
> {
> void myfunc(const A* in)
> {}
> };
> ------------------------------------------------
> sharedptr.cpp
> C:\usr\local\MSVS9.0\VC\INCLUDE\algorithm(29) : error C2064: term does
> not evalu
> ate to a function taking 1 arguments
> class does not define an 'operator()' or a user defined
> conversion opera
> tor to a pointer-to-function or reference-to-function that takes
> appropriate num
> ber of arguments
> sharedptr.cpp(38) : see reference to function template
> instantiation '_F
> n1
> std::for_each<std::_Vector_iterator<_Ty,_Alloc>,boost::_mfi::mf1<R,T,A1>>(_In
> It,_InIt,_Fn1)' being compiled
> with
> [
> _Fn1=boost::_mfi::mf1<void,A,const A *>,
> _Ty=B::tBptr,
> _Alloc=std::allocator<B::tBptr>,
> R=void,
> T=A,
> A1=const A *,
> _InIt=std::_Vector_iterator<B::tBptr,std::allocator<B::tBptr>>
> ]
>
> ---------------------------------------------
>
> Also, is there a way to get the for_each and shared_ptr to work with
> static member functions?
> I tried std::ptr_fun but that one also has a problem that does not
> even try to call the
> shared_ptr::get_pointer
>
> I also tried to enabled BOOST_MEM_FN_ENABLE_CDECL (which is what I use
> for the project) -- that did not help.
> I tried even just having myfunc take const shared_ptr<A> or
> shared_ptr<B> -- that did not work either.
>
>
>
>
> thank you again for your help,
> Vlad
>
>
>
>
>
> On Tue, 24 Feb 2009 17:42 -0800, "Steven Watanabe"
> <watanabesj_at_[hidden]> wrote:
> > AMDG
> >
> > V S P wrote:
> > > struct A: public enable_shared_from_this<A>
> > > {
> > > static void myfunc(const A* in);
> > > };
> > >
> > > for_each (v.begin(),v.end(), boost::mem_fn(&A::myfunc));
> > >
> >
> > A::myfunc is a static member function, so mem_fn doesn't work.
> > If you declare it as a non-static member
> > void myfunc() const;
> > it works.
> >
> > In Christ,
> > Steven Watanabe
> >
> > _______________________________________________
> > Boost-users mailing list
> > Boost-users_at_[hidden]
> > http://lists.boost.org/mailman/listinfo.cgi/boost-users
> --
> V S P
> toreason_at_[hidden]
>
> --
> http://www.fastmail.fm - mmm... Fastmail...
>
-- V S P toreason_at_[hidden] -- http://www.fastmail.fm - Accessible with your email software or over the web
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