functors holding shared_ptr &

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • varnie
    New Member
    • Jun 2008
    • 6

    functors holding shared_ptr &

    good day~

    is it okay to make smth like:
    Code:
    class Foo
    typedef boost::shared_ptr<Foo> FooPtr;
    class MyFunctor{
    const FooPtr [b]&[/b]_pFooPtr;
    public:
      MyFunctor(const FooPtr &p) : _pFooPtr(p) {}
      bool operator()(const FooPtr &other){
        //bla bla
      } 
    };
    or & makes no sense/useless in this case?
    thanks.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    If you are going to do that then the item you are taking the reference to (the pointer in this case) has to be persistent. So the actual answer to your question is that it depends on how you intend to use the class.

    Comment

    • varnie
      New Member
      • Jun 2008
      • 6

      #3
      thanx for clarification. that is exactly what i have expected to hear.

      Comment

      Working...