Actually I want to extract shared_ptr from 'this' object in an another function. For the same suppose we have a situation where a "Thing member function" needs to pass a pointer to "this" object to another function like:
#include "stdafx.h"
#include<memory>
using namespace std;
class Thing {
public:
void foo();
void defrangulate();
};
void Thing::defrangulate()
{
}
void transformIt(shared_ptr<Thing> ptr)
{
ptr->defrangulate();
/* etc. */
}
void Thing::foo()
{
// we need to transformIt this object
shared_ptr<Thing> sp_for_this(this);
transformIt(sp_for_this);
}
int main()
{
shared_ptr<Thing> t1(new Thing);// start a manager object for the Thing
t1->foo();
}
output: Debug Assertion failed! Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
Am I doing any mistake which causing this run time exception ?