[ refa @ 19.12.2005. 08:17 ] @
Kdevelop c++ nakon kompajliranja ovog kodad javi greske /root/testni_projekat/src/matrica.h:36: error: `matrica matrica::operator+(matrica&, matrica&)' must take either zero or one argument /root/testni_projekat/src/matrica.h:37: error: `matrica matrica::operator-(matrica&, matrica&)' must take either zero or one argument /root/testni_projekat/src/matrica.h:38: error: `matrica matrica::operator*(matrica&, matrica&)' must take either zero or one argument *** Exited with status: 2 *** ovo gore je nakon kompajliranja projekat.cpp /root/testni_projekat/src/matrica.h:36: error: `matrica matrica::operator+(matrica&, matrica&)' must take either zero or one argument /root/testni_projekat/src/matrica.h:37: error: `matrica matrica::operator-(matrica&, matrica&)' must take either zero or one argument /root/testni_projekat/src/matrica.h:38: error: `matrica matrica::operator*(matrica&, matrica&)' must take either zero or one argument /root/testni_projekat/src/matrica.cpp:36: error: syntax error before `]' token /root/testni_projekat/src/matrica.cpp:65: error: `matrica matrica::operator+(matrica&, matrica&)' must take either zero or one argument /root/testni_projekat/src/matrica.cpp:80: error: `matrica matrica::operator-(matrica&, matrica&)' must take either zero or one argument /root/testni_projekat/src/matrica.cpp:95: error: `matrica matrica::operator*(matrica&, matrica&)' must take either zero or one argument /root/testni_projekat/src/matrica.cpp:110: error: syntax error at end of input *** Exited with status: 2 *** ovo nakon komajliranja matrica.cpp kode je ispod zasto prijavljuje gresku i zasto ne mogu da koristim template<class T> T x; recim uvijek javi gresku before templets nesto ne znam btw: mislim da mi destruktor nije dobro implementiran. matrica.h #ifndef MATRICA_H #define MATRICA_H /** @author refa */ typedef float tip; class matrica{ private: int column; int row; tip **element; public: matrica(int m,int n); matrica(matrica &x); matrica& operator=(matrica &x); matrica operator+(matrica &,matrica &); matrica operator-(matrica &,matrica &); matrica operator*(matrica &,matrica &); ~matrica(); }; matrica.cpp #endif #include "matrica.h" matrica::matrica(int m,int n) { column=m; row=n; element=new tip*[row]; for(int i=0;i<n;++i) { element=new tip[column]; } } matrica::~matrica() { delete []element; delete element[]; } matrica::matrica(matrica &x) { column=x.column; row=x.row; for(int i=0;i<row;++i) { for(int j=0;j<column;++j) { element[j]=x.element[j]; } } } matrica& matrica::operator=(matrica &x) { column=x.column; row=x.row; for(int i=0;i<row;++i) { for(int j=0;j<column;++j) { element[j]=x.element[j]; } } return *this; } matrica matrica::operator +(matrica &x1,matrica &x2) { if(x1.column==x2.column && x1.row==x2.row) { matrica x(x1); for(int i=0;i<row;++i) { for(int j=0;j<column;++j) { x.element[j]+=x2.element[j]; } } return x; } } matrica matrica::operator -(matrica &x1,matrica &x2) { if(x1.column==x2.column && x1.row==x2.row) { matrica x(x1); for(int i=0;i<row;++i) { for(int j=0;j<column;++j) { x.element[j]-=x2.element[j]; } } return x; } } matrica matrica::operator *(matrica &x1,matrica &x2) { if(x1.row==x2.column) { matrica x(x1); for(int i=0;i<row;++i) { tip sum=0; int j; for(j=0;j<column;++j) { sum+=x.element[j]*x2.element[j]; } x.element[j]=sum; } return x; } projekat.cpp #ifdef HAVE_CONFIG_H #include <config.h> #endif #include "matrica.h" typedef float tip; #include <iostream> #include <cstdlib> using namespace std; int main(int argc, char *argv[]) { matrica a(3,4),b(3,4); return EXIT_SUCCESS; } |