What's your convention for typedef'ing shared_ptr?

后端 未结 16 1702
北恋
北恋 2020-12-13 00:10

I\'m flip-flopping between naming conventions for typedef\'ing the boost::shared_ptr template. For example:

typedef boost::shared_ptr FooPtr;
         


        
16条回答
  •  甜味超标
    2020-12-13 00:31

    I have used both the outer and encapsulated typedef, but ended up with the first,

    typedef boost::shared_ptr FooPtr; 
    

    solely because in combined expressions this looks cleaner than Foo::Ptr.

    Doesn't it bother you that Foo is now "aware" of how it will be passed around?

    Often enough, these classes are creatable through a factory method only:

    struct Foo
    {
         static FooPtr Create() { return FooPtr(new Foo); }
    
       protected:
         Foo() {}
    }
    

    That's kind of "stronger" than encapsulating the typedef, yet a very common pattern.

提交回复
热议问题