#include<iostream>
#include<stdio.h >
#include<cstdlib >
using namespace std;
class matrix
{
int const line; //矩阵的行
int const column; //矩阵的列
long double **matrip;
public:
matrix(int,int);
matrix(const matrix&);
~matrix(){for(int i=0;i<column;i++)delete []matrip[i]; delete []matrip;}
void inputm();
void outputm();
matrix& operator=(matrix&);
matrix verse(matrix); //矩阵转置
};
matrix::matrix(int l,int c):line(l),column(c) //初始化为0阵
{
matrip=new long double *[line];
for(int i=0;i<line;i++)
{
matrip[i]=new long double[column];
for(int j=0;j<column;j++)
matrip[i][j]=0.0;
}
}
matrix::matrix(const matrix& m):line(m.line),column(m.column)
{
matrip=new long double*[line];
for(int i=0;i<line;i++)
{
matrip[i]=new long double[column];
for(int j=0;j<column;j++)
matrip[i][j]=m.matrip[i][j];
}
}
void matrix::inputm()
{
cout<<"请按行输入"<<line<<"*"<<column<<"矩阵数据"<<endl;
for(int i=0;i<line;i++)
for(int j=0;j<column;j++)
cin>>matrip[i][j];
}
void matrix::outputm()
{
cout<<"按行输出的"<<line<<"*"<<column<<"矩阵数据"<<endl;
for(int i=0;i<line;i++)
{
for(int j=0;j<column;j++)
cout<<matrip[i][j]<<" ";
cout<<endl;
}
}
matrix& matrix::operator =(matrix& m)
{
if(line!=m.line||column!=m.column)
{
cout<<"error,their sizes differ";
exit(1);
}
for(int i=0;i<line;i++)
for(int j=0;j<column;j++)
matrip[i][j]=m.matrip[i][j];
return *this;
}
matrix matrix::verse(matrix m)
{
matrix m2(this->column,this->line);
for(int i=0;i<this->line;i++)
for(int j=0;j<this->column;j++)
m2.matrip[j][i]=this->matrip[i][j];
return m2;
}
void main()
{
matrix a(2,2),c(2,2);
a.inputm();
a.outputm();
c=verse(a);
c.outputm();
}
--------------------Configuration: matri - Win32 Debug--------------------
Compiling...
matri.cpp
E:\矩阵\matri.cpp(209) : error C2065: 'verse' : undeclared identifier
执行 cl.exe 时出错.
matri.exe - 1 error(s), 0 warning(s)
明明在类里面声明了,类外定义了的函数怎么运行时说没有声明啊!!!
[此贴子已经被作者于2007-10-29 20:14:24编辑过]