Francesco,
When you use the operator (), it must be on an object, not to a pointer. See your code modified below
Rene Brun
#define nsensor 12 #include "Riostream.h" #include "TMatrixD.h" #include "TVectorD.h" #include "TDecompLU.h" #include "TDecompSVD.h"
class ManyMatrix{
public:
ManyMatrix();
private:
TMatrixD* RcurPtr[nsensor]; TMatrixD* m_tmpPtr; TVectorD* r0curPtr[nsensor]; TVectorD* v_tmpPtr;
};
// Constructor
ManyMatrix::ManyMatrix()
{
for (Int_t i=0; i<nsensor; i++){
RcurPtr[i] = new TMatrixD(3,3); m_tmpPtr=RcurPtr[i]; m_tmpPtr->UnitMatrix(); (*m_tmpPtr)(0,0)=1; (*m_tmpPtr)(1,1)=1; (*m_tmpPtr)(2,2)=1;}
for (Int_t i=0; i<nsensor; i++){
r0curPtr[i] = new TVectorD(3); v_tmpPtr=r0curPtr[i]; (*v_tmpPtr)(2)=100.;
m_tmpPtr->Print();
v_tmpPtr->Print();
}
Francesco Terranova wrote:
> Dear colleagues,
> in these days I'm using quite extensively the linear algebra package
> of ROOT and, in particular, I often need to handle with arrays of
> TMatrixD or TVectorD objects. To do this (see the short example class
> definition below) I defined an array of TMatrixD/TVectorD pointers and
> I manipulate the matrices through them (I'm using version 4.02/00 on a
> Red Hat 7.3 with gcc 2.96). Everything WORKS WELL with CINT but
>
> 1) when I try to compile via aclic (.L manymatrices.C++), it complains
> because it doesn't like things such "m_tmpPtr(0,0)=1;" i.e.
> element assignment via reference to pointer (see the error message below)
> 2) even with CINT, expressions like (RcurPtr[2])(0,0)=1 are not accepted
> and I'm forced to create a temporary pointer equal to RcurPtr[2]
> (m_tmpPtr) and use it to assign elements (m_tmpPtr(0,0)=1)
>
> My conclusion is that my style of programming is wrong and it must be
> a neater way to get the same result (or at least to avoid the CINT shortcut
> I'm using so to get the code compiled). Can you help me?
> Thanks a lot,
> Francesco.
>
>
> ********* CLASS DEFINITION: ************
>
> #define nsensor 12
> #include "Riostream.h"
> #include "TMatrixD.h"
> #include "TVectorD.h"
> #include "TDecompLU.h"
> #include "TDecompSVD.h"
>
> class ManyMatrix{
> public:
> ManyMatrix();
>
> private:
> TMatrixD* RcurPtr[nsensor];
> TMatrixD* m_tmpPtr;
> TVectorD* r0curPtr[nsensor];
> TVectorD* v_tmpPtr;
>
> };
>
> // Constructor
> ManyMatrix::ManyMatrix()
> {
>
> for (Int_t i=0; i<nsensor; i++){
> RcurPtr[i] = new TMatrixD(3,3);
> m_tmpPtr=RcurPtr[i];
> m_tmpPtr->UnitMatrix();
> m_tmpPtr(0,0)=1; m_tmpPtr(1,1)=1; m_tmpPtr(2,2)=1;
> }
>
> for (Int_t i=0; i<nsensor; i++){
> r0curPtr[i] = new TVectorD(3);
> v_tmpPtr=r0curPtr[i];
> v_tmpPtr(2)=100.;
> }
>
> m_tmpPtr->Print();
> v_tmpPtr->Print();
>
> }
>
> ******** ERROR MESSAGE after .L manymatrices.C++ *********
>
> Info in <TUnixSystem::ACLiC>: creating shared library
> /home/terranov/opera/muscatt/./manymatrices_C.so In file included from
> /home/terranov/opera/muscatt/file1GEi2d.h:32,
> from /home/terranov/opera/muscatt/./file1GEi2d.cxx:16:
> /home/terranov/opera/muscatt/./manymatrices.C: In method
> `ManyMatrix::ManyMatrix ()':
> /home/terranov/opera/muscatt/./manymatrices.C:28:
> `this->ManyMatrix::m_tmpPtr' cannot be used as a function
> /home/terranov/opera/muscatt/./manymatrices.C:28:
> `this->ManyMatrix::m_tmpPtr' cannot be used as a function
> /home/terranov/opera/muscatt/./manymatrices.C:28:
> `this->ManyMatrix::m_tmpPtr' cannot be used as a function
> /home/terranov/opera/muscatt/./manymatrices.C:34:
> `this->ManyMatrix::v_tmpPtr' cannot be used as a function g++:
> /home/terranov/opera/muscatt/./file1GEi2d.o: No such file or directory
> Error in <ACLiC>: Compilation failed!
>
Received on Fri Mar 11 2005 - 11:57:54 MET
This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:05 MET