Hi, are there restriction in using overloaded operator () in CINT? Following code run if compiled with g++ isdcpc3:~/mem 201> root ******************************************* * * * W E L C O M E to R O O T * * * * Version 2.23/08 2 November 1999 * * * * You are welcome to visit our Web site * * http://root.cern.ch * * * ******************************************* FreeType Engine v1.1 used to render TrueType fonts. CINT/ROOT C/C++ Interpreter version 5.14.21, Oct 22 1999 Type ? for help. Commands must be C++ statements. Enclose multiple statements between { }. root [0] .L minimal.cc root [1] Mask m(1,2,1.0) root [2] m.show() Mask 1 2 01 __ Error: Can't call Mask::operator()(i,j) in current scope FILE:minimal.cc LINE:75 Possible candidates are... filename line:size busy function type and name (in Mask) filename line:size busy function type and name (in Matrix) Error: Binary operator oprand missing FILE:minimal.cc LINE:75 0|*** Interpreter error recovered *** Here is the code for minimal.cc: #include <iostream.h> #include <assert.h> class Matrix { protected: int fX_dim; //x dimention of the matrix left argument in a(i,j) int fY_dim; //y dimention of the matrix right argument in a(i,j) double * fAdr; //the matrix itself public: Matrix(){ fX_dim=0; fY_dim=0; fAdr=NULL; } Matrix(int x, int y, double z) { fX_dim=x; fY_dim=y; fAdr = new double [fX_dim*fY_dim]; for (int i=0;i<fX_dim*fY_dim;i++){ fAdr[i]=z; } } Matrix(const Matrix & old){ fX_dim=old.fX_dim; fY_dim=old.fY_dim; fAdr = new double [fX_dim*fY_dim]; for (int i=0;i<fX_dim*fY_dim;i++){ fAdr[i]=old.fAdr[i]; } } ~Matrix(){ delete [] fAdr; } Matrix & operator = (const Matrix & old){ if (this != &old){ delete [] fAdr; fX_dim=old.fX_dim; fY_dim=old.fY_dim; fAdr = new double [fX_dim*fY_dim]; for (int i=0;i<fX_dim*fY_dim;i++){ fAdr[i]=old.fAdr[i]; } } return *this; } double operator() (int i, int j) const{ assert(i>-1); assert(i<fX_dim); assert(j>-1); assert(j<fY_dim); return fAdr[i*fY_dim+j]; } }; class Mask : public Matrix { public: Mask(int i,int j,double a): Matrix(i,j,a){} void show(double scale=1.0) const{ char ch; int k; cout<<"Mask "<<fX_dim<<" "<<fY_dim<<"\n"; cout<<" "; for (int j=0;j<fY_dim;j++){ cout<<j%10; } cout<<"\n "; for (int j=0;j<fY_dim;j++){ cout<<'_'; } cout<<"\n"; for (int i=0;i<fX_dim;i++){ cout<<i%10<<'|'; for (int j=0;j<fY_dim;j++){ k=int(10.0*(*this)(i,j)); if (k==10.0){ k=int(' ')-int('0'); } if (k==0.0){ k=174-int('0'); } ch=char(int('0')+k); cout<<ch; } cout<<"|"<<i%10<<"\n"; } cout<<" "; for (int j=0;j<fY_dim;j++){ cout<<'-'; } cout<<"\n"; cout<<" "; for (int j=0;j<fY_dim;j++){ cout<<j%10; } cout<<"\n"; } }; #ifndef __CINT__ main(){ Mask m(1,2,1.0); m.show(); } #endif -- Nicolas Produit
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:17 MET