1

Converting a project from Codeblocks to Visual Studio I encountered this puzzling error from the compiler:

Error 4 error C2228: left of '.swap' must have class/struct/union shared_ptr.hpp Error 3 error C2440: '<function-style-cast>' : cannot convert from 'boost::shared_ptr<T>' to 'boost::shared_ptr<T>' shared_ptr.hpp 384 

Here's the code in question in boost's shared_ptr.hpp

template<class Y> shared_ptr & operator=( shared_ptr<Y> && r ) // never throws { this_type( static_cast< shared_ptr<Y> && >( r ) ).swap( *this ); return *this; } 

I set up a similar but less complicated project and did not get the same error.

2
  • 3
    Could you provide the code where you assign an r-value to a shared_ptr of some sort, and provide the types involved. Commented Nov 26, 2011 at 18:00
  • shared_ptr is used all over the place, I'll check through all assignments to see if I made a mistake Commented Nov 28, 2011 at 9:43

1 Answer 1

4

You probably try to swap two shared_ptr of incompatible types. Make sure that the two shared_ptr point to objects of the same/convertible type.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.