Bonjour
Je suis en train de faire un exo qui consiste à surcharger l'opérateur de multiplication d'une matrice générique (matrice donc le type des éléments est T)
voici mon code
Matrice.h
Matrice.cpp
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 #pragma once #include<vector> #include<iostream> using namespace std; template <typename T> class Matrice { public: enum error {WRONG_SIZE}; vector<vector<T>> mTableau; Matrice(void); ~Matrice(void); friend Matrice<double> saisi_matrice(); Matrice operator*(Matrice); }; Matrice<double> saisi_matrice();
L'erreur de compilation est
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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 #include "Matrice.h" template <typename T> Matrice<T>::Matrice(void) { } template <typename T> Matrice<T>::~Matrice(void) { } template<typename T> Matrice<T> Matrice<T>::operator*(Matrice<T> matrice) { Matrice<T> mResult; int nombreLignes=mTableau.size(); int nombreColonnes=mTableau[0].size(); if (((nombreLignes)!=matrice.mTableau[0].size())|| (nombreColonnes!=matrice.mTableau.size())) { throw WRONG_SIZE; } vector<vector<T>> tableauTemp(nombreLignes,vector<T>(nombreColonnes)); for (unsigned int i(0); i<nombreLignes;i++) { for (unsigned int j(0);j<nombreColonnes;j++) { tableauTemp[i][j]=mTableau[i][j]*matrice.mTableau[j][i]; } } mResult.mTableau=tableauTemp; return mResult; } Matrice<double> saisi_matrice() { unsigned int nombreLignes; unsigned int nombreColonnes; cout<<"Nombre de lignes"<<endl; cin>>nombreLignes; cout<<"Nombre de colonnes"<<endl; cin>>nombreColonnes; Matrice<double> result; vector<vector<double>> tableau(nombreLignes,vector<double>(nombreColonnes)); result.mTableau=tableau; for(unsigned int i(0);i<nombreLignes;++i) for(unsigned int j(0);j<nombreColonnes;++j) { cout<<"tableau["<<i+1<<","<<j+1<<"]="; cin>>result.mTableau[i][j]; } return result; }
Merci de vos aides1>Main.obj : error LNK2001: symbole externe non résolu "public: class Matrice<double> __thiscall Matrice<double>::operator*(class Matrice<double>)" (??D?$Matrice@N@@QAE?AV0@V0@@Z)
Partager