bonjour je voudrais faire un template de classe (pour apprendre) Matrice :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifndef MATRICE_HH
#define MATRICE_HH
 
#include "Exception.hh"
 
template<typename Tn=float>
class Matrice {
	private:
		int MATnombreLignes;
		int MATnombreColonnes;
		Tn **MATtableau;		
	public:
		Matrice(Tn valeurDefaut, int lignes, int colonnes) throw(Exception);
		~Matrice();
};
 
#include "Matrice.cc"
 
#endif
Matrice.cc :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
template<typename Tn>
Matrice<Tn>::Matrice(Tn valeurDefaut, int lignes, int colonnes) throw(Exception) :
MATnombreLignes(lignes), MATnombreColonnes(colonnes), MATtableau(NULL)
{
	try {
		MATtableau=new Tn[lignes];
		for(int iBoucleLigne=0;iBoucleLigne<lignes;iBoucleLigne++) {
			MATtableau[iBoucleLigne]=new Tn[colonnes];
			for(int iBoucleColonne=0;iBoucleColonne<colonnes;iBoucleColonne++)
				MATtableau[iBoucleLigne][iBoucleColonne]=valeurDefaut;
		}
	}
	catch(std::bad_alloc& ba) {
		throw Exception("Memory error.");
	}
}
 
template<typename Tn>
Matrice<Tn>::~Matrice() {
	if (MATtableau)
		for(int iBoucleLigne=0;iBoucleLigne<MATnombreLignes;iBoucleLigne++)
			if (MATtableau[iBoucleLigne])
				delete MATtableau[iBoucleLigne];
}
Erreur :

Matrice.cc: In constructor ‘Matrice<Tn>::Matrice(Tn, int, int) [with Tn = int]’:
main.cc:8: instantiated from here
Matrice.cc:6: erreur: cannot convert ‘int*’ to ‘int**’ in assignment
make: *** [main.oo] Erreur 1
Pouvez vous m'éclaircir ?

Au passage je demande que utiliser comme conteneur ? un tableau comme je veux faire, des vector, list ?