In article <dr**********@opal.icpnet.pl>,
"Sebastor" <br********@onet.pl> wrote:
Hi
I create bitmap array :
Graphics::TBitmap ***bitmap;
bitmap = new Graphics::TBitmap**[x];
for (int s=0;s<x;s++)
{
bitmap[s] = new Graphics::TBitmap*[y];
for (int u=0;u<y;u++)
bitmap[s][u] = new Graphics::TBitmap;
}
How can i delete this array ?
for (int s=0;s<x;s++)
{
for (int u=0;u<y;u++)
delete bitmap[s][u];
delete bitmap[s];
}
or I have to use "delete[]" command?
This is a great example why you should use the standard containers...
template < typename T >
class Array {
int _x;
std::deque< T > _array;
public:
Array( int x, int y ): _x( x ), _array( x * y ) { }
const T& operator()( int x, int y ) const {
return _array[ x * _x + y ];
}
T& operator()( int x, int y ) {
return _array[ x * _x + y ];
}
};
Now create your array:
Array< Graphics::TBitmap > bitmap( x, y );
You get proper destruction as well as copy semantics for free.