Advertisement

03.22.2008 at 09:35PM PDT, ID: 23262301
[x]
Attachment Details

boost shared_ptr assignment problem

Asked by josgood in C++ Programming Language

Tags: C++, boost, shared, ptr

The contrived example below illustrates a problem that I'm having.

Running with VS2003, built in unmanaged debug mode, the second
    anA.SetPtr(aB)
encounters an error "...has requested the Runtime to terminate it in an unusual way..."

What am I doing wrong?

#include "boost/smart_ptr.hpp"

class A;
class B {
public:
   void SetPtr(A& anA) {
      pA.reset<A>(&anA);
   }
private:
   boost::shared_ptr<A> pA;
};

class A {
public:
   void SetPtr(B& b) {
      b.SetPtr(*this);
   }
};

 
int main() {
   A anA;
   B aB;
   anA.SetPtr(aB);
   anA.SetPtr(aB);
}
Start Free Trial
[+][-]03.23.2008 at 11:40AM PDT, ID: 21190418

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.23.2008 at 12:51PM PDT, ID: 21190622

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.23.2008 at 01:41PM PDT, ID: 21190737

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C++ Programming Language
Tags: C++, boost, shared, ptr
Sign Up Now!
Solution Provided By: ravenpl
Participating Experts: 1
Solution Grade: A
 
 
[+][-]03.23.2008 at 02:20PM PDT, ID: 21190835

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906