Bonjour,
j'ai quelques erreurs je suis rest� tellement longtemps dessus que j'ai d�cid� de m'inscrire sur le site pour avoir un peu d'aide. Merci d'avance.
Alors je vous montre d'une part le code du main :
Ma classe :
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 #include "matrice.hpp" #include <iostream> #include <cmath> int main() { unsigned int N=4; std::vector<double> V(N,2.); Matrice A(N,1), B(V) , C(N); C=A+B; //C(3,2)=7.0; std::cout<<"La matrice C est : "<<C<<std::endl; std::cout<<" Sa taille est : "<<C.taille(); std::cout<<"Sa trace est : "<<C.taille(); return 0; }
Ainsi que le code des m�thodes :
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 #include <vector> #include <iostream> class Matrice { private: int N; std::vector<double> coeff; public: int taille() const; double trace() const; friend Matrice & operator+(Matrice & , Matrice &); //double & operator() (int, int); Matrice(const std::vector<double> &); Matrice(int, double x=0); }; Matrice & operator+(Matrice & , 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
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 #include "matrice.hpp" #include <vector> #include <iostream> int Matrice::taille() const { return N; //on aurait pu ici le mettre en inline) } //double Matrice::operator() (int i, int j) { //double k; //k=coeff[N*i+j]; //return k; //} int Matrice::trace() const { double t=0; for (int i=0; i<N; i++) {t=t+ coeff[N*i+i]; } return t; } Matrice& operator+(Matrice & A, Matrice & B) { std::vector<double> T((N-1)*(N-1)); for (int i=0; i<=(N-1)*(N-1);i++) { for (int j=0; j<=(N-1)*(N-1);j++) { T[N*i + j]= A[N*i+j] + B[n*i+j]; } } return T; } //on a fait les accesseurs on fait maintenant les constructeurs. Matrice::Matrice (int p, double x):N(p), coeff(p*p,x) {} Matrice::Matrice(const std::vector <double> & V):N(V.size()), coeff(V.size()*V.size(),0) { for (int i = 0; i<N;i++) {coeff [N*i+i]=V[i];} }
J'ai des erreurs du type :
matrice.cpp:21:6: error: prototype for �int Matrice::trace() const� does not match any in class �Matrice�
int Matrice::trace() const {
^
In file included from matrice.cpp:1:0:
matrice.hpp:12:9: error: candidate is: double Matrice::trace() const
double trace() const;
^
matrice.cpp: In function �Matrice& operator+(Matrice&, Matrice&)�:
matrice.cpp:31:25: error: �N� was not declared in this scope
std::vector<double> T((N-1)*(N-1));
^
matrice.cpp:34:29: error: �n� was not declared in this scope
T[N*i + j]= A[N*i+j] + B[n*i+j];
^
matrice.cpp:38:10: error: invalid initialization of non-const reference of type �Matrice&� from an rvalue of type �Matrice�
return T;
^
In file included from matrice.cpp:1:0:
matrice.hpp:17:2: note: after user-defined conversion: Matrice::Matrice(const std::vector<double>&)
Matrice(const std::vector<double> &);
^
J'aimerais bien qu'on m'aide, merci beaucoup en tout cas.![]()
Partager