|
Boost : |
From: Slawomir.Czarko_at_[hidden]
Date: 2000-12-05 13:22:02
Hi,
I have a problem with the code below. It uses boost::shared_ptr. It
crashes on the assertion in main. I debugged it and it looks like
with
C++Builder 5 (bcc32 version is 5.5) destructor for sp1_[ 0 ] is
called
twice and for sp2_[ 0 ] never. When using gcc 2.95.2 no destructor is
called even if the line #if 1 is changed to #if 0. It works fine with
MSVC++ 6 SP3, though.
Can anyone suggest a workaround or explain to me what am I doing
wrong?
I want to put boost::shared_ptr objects into an array which then will
be used to initialize a STL container.
Thank you.
Slawek
//////////
#include <cassert>
#include <boost/smart_ptr.hpp>
#include <boost/utility.hpp>
struct foo
{
foo()
{
++count;
}
~foo()
{
--count;
}
static int count;
};
int foo::count = 0;
void test()
{
#if 1
typedef int T1;
typedef boost::shared_ptr< T1 > Ptr_T1;
Ptr_T1 sp1_[] =
{
Ptr_T1( new T1() )
};
#endif
typedef foo T2;
typedef boost::shared_ptr< T2 > Ptr_T2;
Ptr_T2 sp2_[] =
{
Ptr_T2( new T2() )
};
throw 1;
}
int main()
{
try
{
test();
}
catch( ... )
{
}
assert( 0 == foo::count );
return 0;
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk