Salut,
tu peux faire un "patron" pour avoir des tailles dynamiques (matrice carrée ou non)
puis faire des macros pour init et affichage
Dans un deuxième temps, on peut "templatiser" aussi le type de l matrice en plus des tailles.
Exemple :
// Un patron de matrice (char)
template<size_t N, size_t M>
struct MAT
{
char _m[N][M];
};
// Macro init
#define IDENTMAT(mat,N,M) {memset(mat, '0', (N*M)*sizeof(char));}
// Macro log
#define LOGMAT(mat,N,M) { \
for(int i=0;i<N;i++) { \
for(int j=0;j<M;j++) \
std::cout << (mat)->_m[i][j] << " "; \
std::cout << std::endl; } }
typedef MAT<4,4> MAT4X4; // exemple avec typedef taille connue
int _tmain(int argc, _TCHAR* argv[])
{
// Avec un typedef pour une matrice 4X4 allouée sur le heap
MAT4X4* pMat4X4 = new MAT4X4;
IDENTMAT(pMat4X4,4,4);
LOGMAT(pMat4X4,4,4);
delete pMat4X4;
std::cout << std::endl << std::endl;
// sans typedef pour une matrice 10X10 sur la stack
MAT<10,10> mat10X10;
IDENTMAT(&mat10X10,10,10);
mat10X10._m[0][0] = 'X';
LOGMAT(&mat10X10,10,10);
std::cout << std::endl << std::endl;
// Matrice non carrée
MAT<10,5> mat10X5;
IDENTMAT(&mat10X5,10,5);
LOGMAT(&mat10X5,10,5);
return 0;
}
bye...