I can\'t understand why does the following code produce memory leaks (I am using boost::shared_ptr with static class instance). Could someone help me?
At a guess the CRT is reporting a false positive - the following code illustrates that the shared pointer is working correctly, at least with g++
#include
#include "boost/shared_ptr.hpp"
using namespace std;
using namespace boost;
struct R {
R() {
cerr << "ctor" << endl;
}
~R() {
cerr << "dtor" << endl;
}
};
struct A {
static shared_ptr ptr;
A() {
ptr = shared_ptr(new R);
}
};
shared_ptr A::ptr;
static A a;
int main() {
}
It prints:
ctor
dtor