RE: [ROOT] example in the code

From: Philippe Canal (pcanal@fnal.gov)
Date: Thu Feb 28 2002 - 00:57:49 MET


Hi Nicolas,

C++ prohibits assigning temporary object to references that are not constant.
TMatrixD::Apply expect a reference to TElementActionD object which is NOT constant,
thus you need to pass non-temporary objects.

To work-around the issue use:

   ApplyFunction sinfunc(TMath::Sin);
   ApplyFunction cosfunc(TMath::Cos);
   m.Apply(sinfunc);
   m1.Apply(cosfunc);

Cheers,
Philippe.

-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Nicolas Produit
Sent: Tuesday, February 26, 2002 10:21 AM
To: roottalk@pcroot.cern.ch
Subject: [ROOT] example in the code


Hi,
I try to figure out how to use use TMatrixD Apply method.
Looking at the example in the TMatrixD code (and making some obvious
corrections like TElementActionD rather then TElementAction)
I get the following piece of code:



#include "TMatrixD.h"
void foo(TMatrixD &m, TMatrixD &m1)
{
   typedef  double (*dfunc_t)(double);
   class ApplyFunction : public TElementActionD {
     dfunc_t fFunc;
     void Operation(Double_t &element) { element=fFunc(element); }
   public:
     ApplyFunction(dfunc_t func):fFunc(func) {}
   };
   m.Apply(ApplyFunction(TMath::Sin));
   m1.Apply(ApplyFunction(TMath::Cos));
}

But trying to compile it I got:

g++ -c -Wall -g -D_REENTRANT -I/isdc/sw/root/3.02.07/gcc/2.95.2/include 
bla.C
bla.C: In function `void foo(TMatrixD &, TMatrixD &)':
bla.C:11: initialization of non-const reference type `class 
TElementActionD &'
bla.C:11: from rvalue of type `foo(TMatrixD &, TMatrixD &)::ApplyFunction'
/isdc/sw/root/3.02.07/gcc/2.95.2/include/TMatrixD.h:337: in passing 
argument 1 of `TMatrixD::Apply(TElementActionD &)'
bla.C:12: initialization of non-const reference type `class 
TElementActionD &'
bla.C:12: from rvalue of type `foo(TMatrixD &, TMatrixD &)::ApplyFunction'
/isdc/sw/root/3.02.07/gcc/2.95.2/include/TMatrixD.h:337: in passing 
argument 1 of `TMatrixD::Apply(TElementActionD &)'


Could you hint me a correct way of doing it?

Thanks




-- 
Nicolas Produit
INTEGRAL Science Data Center    Phone:  +41 22 950 91 40
16, Chemin d'Ecogia             Fax:    +41 22 950 91 33
CH-1290 Versoix                 www:    http://isdc.unige.ch/



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:43 MET