That's fine. But in this case... CINT complains! More precisely:
Error: Symbol m_tmpPtr is not defined in current scope
FILE:manymatrices2.C LINE:28
Error: Can not access pointer to function 0x0 from interpreter(1)
FILE:/home/terranov/opera/muscatt/./manymatrices2.C LINE:28
Warning: Re-initialization ignored const (*m_tmpPtr)(1,1)
FILE:manymatrices2.C LINE:28
*** Interpreter error recovered ***
2) If I use my old code and I type
.L manymatrices.C ManyMatrix* test = new ManyMatrix()everything is OK (but of course I fail when I try to complile)
How can I write the code so that both the interpreter and the complier
do not complain?
Cheers,
Francesco.
-----Messaggio originale-----
Da: Rene Brun Inviato: ven 11/03/2005 11.57 A: Francesco Terranova Cc: roottalk_at_pcroot.cern.ch Oggetto: Re: [ROOT] Arrays of TMatrixD,TVectorDFrancesco,
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 Sun Mar 13 2005 - 19:53:53 MET
This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:06 MET