Search code examples
c++booststaticinitializationshared-ptr

How do I define a static boost shared pointer?


How do I define cloud outside the class?

typedef pcl::PointCloud<pclPoint> pclPointCloud
class Deformer{
    public:
    static pclPointCloud::Ptr cloud;
};
pclPointCloud::Ptr Deformer::cloud = ??;    // What to write here

Can't I define it using NULL, or something like pclPointCloud::Ptr Deformer::cloud = boost::shared_ptr<pclPointCloud>(NULL);?


Solution

  • It will be default constructed if you simply remove the = ?? part. This is the same as setting it to null (i.e. calling reset()).

    By the way, something interesting about class statics is that even POD types like raw pointers and integral types will by default have the value zero when your program starts. So even an "uninitialized" raw pointer will be null.