本文介绍了类矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 此程序已编译,但不想启动。为什么? #include< iostream> 使用命名空间std; class matrix2x2 { $ b $私人: 双M [2] [2]; 公开: matrix2x2(const double tab [] [2]); matrix2x2(double,double,double,double); matrix2x2(); matrix2x2 operator +(matrix2x2); matrix2x2 operator =(matrix2x2); matrix2x2 operator - (){ cout<<" operator - " <<结束; M [0] [0] = - M [0] [0]; M [0] [1] = - M [0] [1 ]; M [1] [0] = - M [1] [0]; M [1] [1] = - M [1] [1 ]; 返回*这个; } 朋友ostream&运算符<< (ostream os,const matrix2x2 X); double det(){return M [0] [0] * M [1] [1] -M [1] [0] * M [0 ] [1];} }; matrix2x2 :: matrix2x2(const double tab [] [2]){ int i,j; for(i = 1; i< 2; i ++) for(j = 0; j< 2; j ++) M [i] [j] = tab [i] [j]; } matrix2x2 :: matrix2x2(double a,double b,双c,双d){ M [0] [0] = a; M [0] [1] = b; M [1] [0] = c; M [1] [1] = d; } matrix2x2 :: matrix2x2(){ M [0] [0] = 0; M [0] [1] = 0; M [1] [0] = 0; M [1] [1] = 0; } matrix2x2 matrix2x2 :: operator +(matrix2x2 X){ matrix2x2 T; TM [0] [0] = M [0] [0] + XM [ 0] [0]; TM [0] [1] = M [0] [1] + XM [0] [1]; TM [1] [0] = M [1] [0] + XM [1] [0]; TM [1] [1] = M [1] [1] + XM [1] [1 ]; 返回T; } matrix2x2 matrix2x2 :: operator =(matrix2x2 X){ matr ix2x2 T; TM [0] [0] = XM [0] [0]; TM [0] [1] = XM [0] [1] ; TM [1] [0] = XM [1] [0]; TM [1] [1] = XM [1] [1]; 返回T; } / * matrix2x2 matrix2x2 :: operator-(){ matrix2x2 T; TM [0] [0] = - XM [0] [0]; TM [0] [1] = - XM [0] [ 1]; TM [1] [0] = - XM [1] [0]; TM [1] [1] = - XM [1] [ 1]; 返回T; } * / // int main() int main(int argc,char ** argv) { const double tab [] [2] = {{1.5,2.5},{ 3.5,4.5}}; matrix2x2 A(制表符),B(1.0,0.0,0.0,-1.0),C = A + B,D; D = -C; cout<< \ nMacierz A: << A << ,macierz B: << B << ,macierz C: << C << ,macierz D: << D << ,wyznacznik macierzy A:" << A.det()//-2.0 << ,wyznacznik macierzy B:" << B.det()//-1.0 << ,wyznacznik macierzy C:" << C.det()// 0.0 << ,wyznacznik macierzy D:" << D.DET(); // 0.0 返回0; } 解决方案 wo********@gmail.com 写道: 此程序已编译,但不想启动。为什么? 我不知道。你似乎有一个非常奇怪的编译器。代码中包含了很多错误,这些错误会阻止它被我所知道的任何C ++ 编译器接受。 代码包含很多错误(...) 我用Microsoft Visual C ++和我只看到两个错误: a.obj:错误LNK2001:未解析的外部符号"类 std :: basic_ostream< char, struct std :: char_traits< char> > &安培; __cdecl operator<<(class std :: basic_ostream< char,struct std :: char_traits< char>,class matrix2x2)" (?? 6 @ YAAAV? basic_ostream @ DU? This program is compiled, but it is not wanted to start up. Why?#include <iostream>using namespace std; class matrix2x2{private:double M[2][2];public:matrix2x2 (const double tab[][2]);matrix2x2(double,double,double,double);matrix2x2();matrix2x2 operator + (matrix2x2);matrix2x2 operator = (matrix2x2);matrix2x2 operator - () {cout <<"operator -" << endl;M[0][0]=-M[0][0];M[0][1]=-M[0][1];M[1][0]=-M[1][0];M[1][1]=-M[1][1];return *this;} friend ostream& operator << (ostream os, const matrix2x2 X);double det() {return M[0][0]*M[1][1]-M[1][0]*M[0][1];}}; matrix2x2::matrix2x2 (const double tab[][2]){int i,j;for (i=1;i<2;i++)for (j=0;j<2;j++)M[i][j]=tab[i][j];} matrix2x2::matrix2x2(double a, double b, double c, double d) {M[0][0]=a;M[0][1]=b;M[1][0]=c;M[1][1]=d;} matrix2x2::matrix2x2(){M[0][0]=0;M[0][1]=0;M[1][0]=0;M[1][1]=0;} matrix2x2 matrix2x2::operator + (matrix2x2 X){matrix2x2 T;T.M[0][0]=M[0][0] + X.M[0][0];T.M[0][1]=M[0][1] + X.M[0][1];T.M[1][0]=M[1][0] + X.M[1][0];T.M[1][1]=M[1][1] + X.M[1][1];return T;} matrix2x2 matrix2x2::operator = (matrix2x2 X){matrix2x2 T;T.M[0][0]=X.M[0][0];T.M[0][1]=X.M[0][1];T.M[1][0]=X.M[1][0];T.M[1][1]=X.M[1][1];return T;} /*matrix2x2 matrix2x2::operator- (){matrix2x2 T;T.M[0][0]=-X.M[0][0];T.M[0][1]=-X.M[0][1];T.M[1][0]=-X.M[1][0];T.M[1][1]=-X.M[1][1];return T;}*///int main()int main(int argc, char **argv){const double tab[][2]= {{1.5, 2.5}, {3.5, 4.5}}; matrix2x2 A(tab), B(1.0, 0.0, 0.0, -1.0), C = A + B, D; D = -C; cout << "\nMacierz A: " << A<< ", macierz B: " << B<< ", macierz C: " << C<< ", macierz D: " << D<< ", wyznacznik macierzy A: " << A.det() //-2.0<< ", wyznacznik macierzy B: " << B.det() //-1.0<< ", wyznacznik macierzy C: " << C.det() // 0.0<< ", wyznacznik macierzy D: " << D.det(); // 0.0 return 0;} 解决方案 wo********@gmail.com wrote: This program is compiled, but it is not wanted to start up. Why? I don''t know. You seem to have a very strange compiler. The code containsquite a lot of errors that would prevent it from being accepted by any C++compiler I know. The code contains quite a lot of errors(...) I use Microsoft Visual C++ and I see only two error: a.obj : error LNK2001: unresolved external symbol "classstd::basic_ostream<char,struct std::char_traits<char> > & __cdecloperator<<(class std::basic_ostream<char,struct std::char_traits<char>,class matrix2x2)" (??6@YAAAV?basic_ostream@DU? 这篇关于类矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-26 19:58