Реализовал класс комплексных чисел ComNum. Переопределить операции сложения, вычитания и ввод/вывод в поток. Создал шаблон класса матриц.
#include<iostream> #include<conio.h> using namespace std; template<class Neo> class Ma3X { public: int a,b; Neo **mas; Ma3X(){} Ma3X(int aa, int bb) { a=aa; b=bb; Neo **mas=new Neo*(a); for (int j=0;j<a;j++) mas[j]=new Neo[b]; } void ToPrint() { for(int j=0;j<a;j++) { for(int i=0;i<b;i++) cout<<mas[i][j]; } } void ToFill() { for(int j=0;j<a;j++) for(int i=0;i<b;i++) cin>>mas[i][j]; } void ToAdd(Ma3X ma3x) { for(int j=0;j<a;j++) for(int i=0;i<b;i++) mas[i][j]=mas[i][j]+ma3x.mas[i][j]; } void ToSub(Ma3X ma3x) { for(int j=0;j<a;j++) for(int i=0;i<b;i++) mas[i][j]=mas[i][j]-ma3x.mas[i][j]; } }; class ComNum { friend ostream& operator << (ostream& os,ComNum& obj); friend iostream& operator >> (istream& os,ComNum& obj); public: int re; int im; ComNum operator+ (ComNum oo); ComNum operator- (ComNum oo); ComNum() { re=im=0; }; ComNum(int RE,int IM) { re=RE; im=IM; }; }; ComNum ComNum::operator+ (ComNum oo) { ComNum ExNum; ExNum.re=re+oo.re; ExNum.im=im+oo.im; return ExNum; } ComNum ComNum::operator- (ComNum oo) { ComNum ExNum; ExNum.re=re-oo.re; ExNum.im=im-oo.im; return ExNum; } ostream& operator << (ostream& os,ComNum& obj) { os<<"Re = "<<obj.re<<" "<<"Im = "<<obj.im<<endl; } iostream& operator >> (istream& os,ComNum& obj) { cout<<"Enter Re"<<endl; os>>obj.re; cout<<"Enter Im"<<endl; os>>obj.im; } int main() { ComNum a(1,2); ComNum b; ComNum c; cout<<"A: "<<a; cout<<"B: "<<b; cin>>b; cout<<"B: "<<b; c=a+b; cout<<"C: "<<c; Ma3X <int> mint(3,3); Ma3X <float> mflo(4,4); Ma3X <ComNum> mcom(2,2); mint.ToFill(); mint.ToPrint(); getch(); }
При работе с классом матриц возникает ошибка, как исправить?