Opened 17 years ago

Closed 16 years ago

#71 closed Support Requests (Invalid)


Reported by: nobody Owned by: Peter Dimov
Milestone: Component: smart_ptr
Version: None Severity:
Keywords: Cc:


I have used the shared_ptr class in some code I wrote 
a couple of years ago using Microsoft Visual C++ 5.0, 
and it worked great!  Now I am trying to re-compile 
this code using Microsoft Visual C++6.0 and am getting 
some errors.
I have tried everything I can think of, including 
getting the latest version of the library from the 
boost web site, but I am still getting the same error.

I am using the shared_ptr with a class 
called 'CVFolder'.

The code is something like this.

CVFolder* pFolder = new CVFolder();

class boost::shared_ptr<class CVFolder>* pSharedPtr;

pSharedPtr = new boost::shared_ptr<CVFolder>(pFolder);

When I compile, I get the following error.

error C2514: 'boost::shared_ptr<class CVFolder>' : 
class has no constructors

Again, this error did not occur with VS5.0

Any help is appreciated.



Change History (2)

comment:1 Changed 17 years ago by nobody

Logged In: NO 

Your code looks bogus.

It should be written

// declare your shared pointer to point on CVFolder
// and assign to it you newly allocated object
boost::shared_ptr<CVFolder> pSharedPtr( new CVFolder() );

This is all done in one instruction.

If you need to do it in two instructions here is how it should be written

// declare the pointer variable
boost::shared_ptr<CVFolder> pSharedPtr;

// assign to it the newly created object
pSharePtr.reset( new CVFolder() );

Note that for assignement between shared_ptr you can use the = operator.

// declare another shared_ptr variable
boost::shared_ptr<CVFolder> pOtherSharedPtr;

// assign shared_ptr value using =
pOtherSharedPtr = pSharedPtr;

It will only work between shared_ptr. 

comment:2 Changed 16 years ago by Peter Dimov

Status: assignedclosed
Note: See TracTickets for help on using tickets.