Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

(C++) shared_ptr.hpp: Cannot convert 'Y *' to 'Widget *'

 

Compile error.

 

 

 

 

 

Full error message

 

 

[C++ Error] shared_ptr.hpp(124): E2034 Cannot convert 'Y *' to 'Widget *'

 

 

 

 

 

 

Cause

 

IDE: C++ Builder 6.0

Compiler: Borland BCC32.EXE version 6.0.10.157

Boost version: 1.35.0.

 

A boost::shared_ptr is either uninitialized or initialized with a pointer. Initializing with 0 is not a valid initialization and therefore not possible.

 

 

#include <boost/shared_ptr.hpp>

 

int main()

{

boost::shared_ptr<Widget> w(0); //ERROR! Cannot initialize with 0

//Should be the code below:

//boost::shared_ptr<Widget> w(new Widget);

}

 

 

 

 

 

 

Solution

 

Initialize the boost::shared_ptr.

 

 

#include <boost/shared_ptr.hpp>

 

int main()

{

boost::shared_ptr<Widget> w(new Widget);

}

 

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.