> Can somebody explain [to] me how can I use matrixes with dinamic
memory?
I use malloc and free (NOT new & delete).
I want to access to the matrix like Matrix[r][c]
but I don't know how to do that with pointers and malloc & free.
If I declare 4 static matrices of 576x720,
the program breaks down (How is it possible?)
So I must use dinamic memory (I suppose).
Use a class who's operator[] returns a pointer to the type.
Example:
template < class T>
class dynamic_2d_arra y
{
public:
dynamic_2d_arra y(int row, int col):m_row(row) ,m_col(col),
m_data((row!=0& &col!=0)?new T[row*col]:NULL){}
dynamic_2d_arra y(const
dynamic_2d_arra y&src):m_row(sr c.m_row),m_col( src.m_col),
m_data((src.m_r ow!=0&&src.m_co l!=0)?new T[src.m_row*src.m _col]:NULL){
for(int r=0;r<m_row;++r )for(int c=0;c<m_col;++c ) (*this)[r][c] =
src[r][c];
}
~dynamic_2d_arr ay(){if(m_data) delete []m_data;}
inline T* operator[](int i) {return (m_data + (m_col*i));}
inline T const*const operator[](int i) const {return (m_data +
(m_col*i));}
protected:
dynamic_2d_arra y& operator=(const dynamic_2d_arra y&);
private:
const int m_row;
const int m_col;
T* m_data;
};
For more information, check out the following link:
http://www.tek-tips.com/faqs.cfm?fid=5575