matrix array

Nikolai Yu. Zaitsev (Nikolai.Zaitsev@cern.ch)
Tue, 14 Jul 1998 14:50:11 +0200 (METDST)


Dear rooters,

Tracking needs an array of matrices - individual rotations for each
detector.
To find a solution I wrote the test program Mtest.C which creates TMatrix
objects m and **f. f is an array of pointers. m is for the crosscheck that
I am doing everything fine.

At some point when I try to fill *f[0] matrix (see comment in the code) I
get the message:

Error: Can't call TMatrix::operator[]() in current scope
Error: improper lvalue

I have the solution avoiding call of []() operator:

TMatrix* tmp(2,2);
tmp=f[0];
tmp(1,1)=15.5;

but it seems to me not elegant.

What can I do?

Thanks in advance,
Nikolai.

-------------------------Mtest.C----------------------------
#include <iostream.h>

void Mtest()
{
cout << "Start" << endl;
TMatrix *m = new TMatrix(2,2);
cout <<"M init.ed " << m << endl;

TMatrix **f = new TMatrix[2];
cout << "Pointers array declared" << endl;
for(int i=0;i<2;i++)
TMatrix *f[i]= new TMatrix(2,2);
cout << "f=" << f << " f0=" << f[0] << " f1=" << f[1] << endl;
cout << "Array init.ed" << endl;

Print("m ",*m);

Print("f0",*f[0]);

// f[1](1,0)=-100.;
Print("f1",*f[1]);

m(0,0)=1.;
m(1,1)=-1.5;

Print("m ", *m);

*f[0]=*m;

// here it tells : Can't call TMatrix::operator[]() in current scope
f[0](1,1)=15.5;

Print("f0",*f[0]);

}

// small function to print the matrix
void Print(char s[2],TMatrix &a)
{
cout << s[0]<<s[1] << endl;
int Ncols=a.GetNcols();
int Nrows=a.GetNrows();
cout <<"Nc="<<Ncols<<" Nr="<<Nrows<<endl;

for (int i=0;i<Nrows;i++)
{
for(int j=0;j<Ncols;j++)
cout << a(i,j) << " ";
cout << endl;
}
cout << endl;
}