There is a class

class Camera { public: void initCamera(); void destroyCamera(); static boost::shared_ptr<Camera> createCamera(); ~Camera(); private: Camera(); static boost::shared_ptr<Camera> cameraInstance; }; 
  1. When compiling into Camera.cpp on the line:

     boost::shared_ptr<Camera> Camera::cameraInstance = NULL; 

    The error is:

    error error C2440: initialization: unable to convert int to boost :: shared_ptr

  2. In the destructor on the line

     cameraInstance = NULL; 

    I get an error:

    error C2679: binary '=': operator not found that accepts the right operand of the 'int' type (or there is no acceptable conversion)

How to fix?

  • one
    and where is sharepoint? - Max Zhukov
  • one
    looked at the code, it seems that you are trying to make manual control of shared_ptr. What is already there is wrapped in one more :). - KoVadim

3 answers 3

cameraInstance.reset()

    Use nullptr instead of NULL . This is a more correct way to write a null pointer, and shared_ptr has a special constructor that accepts std::nullptr_t .

       >>boost::shared_ptr<Camera> Camera::cameraInstance = NULL; 

      when a shared point is initialized, its pointer will already be referenced to "nothing". It makes no sense to zero it; there really isn’t an = operator.

      You can reset() pointer through the reset() method, but the most correct is to first call the constructor of the object that you are interested in.