(C++) shared\_ptr.hpp: Cannot convert 'Y \' to 'Widget \'

February 24, 2017 · View on GitHub

 

 

 

 

 

(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 }

 

 

 

 

 

Solution

 

Initialize the boost::shared_ptr.

 


#include <boost/shared_ptr.hpp> int main() {   boost::shared_ptr<Widget> w(new Widget); }