Re: Just another SEGV ...

From: Volker Hejny (V.Hejny@fz-juelich.de)
Date: Tue Aug 17 1999 - 10:41:34 MEST


On Tue, Aug 17, 1999 at 10:14:56AM +0200, Marco van Leeuwen wrote:
> 
> As far as I can tell, you want to make a (arbitrary size) array of EMModule
> objects. In my experience, a possible way to go about it, is using an array
> of pointers to object (instances). This works fine when using the TObjArray
> class, but probably you can also implement something alike by yourself.

Yes, my first idea was to implement it like this (as an array of pointers
to the object), but due to the problems and the fact that this array
is more or less 'static', I just built an array of the objects.

> >[...]
> >
> >class EMCalo {
> > private:
> >  EMModule *Modules;
> 
> I don't known whether this is correct. Formally, you want to have a
> EMModule**, I think. If this doesn't work, you can try a general pointer:
> void* .

No, I don't want to have EMModule** (see above).

> [...] 
> >
> >EMCalo::EMCalo(int modnum) {
> >  Modules = new EMModule[modnum];
> 
> I think that what you're doing here doesn't work, since the
> Interpreter/compiler doesn't know which arguments it should use in the
> constructor calls of each EMModule.

Of course it does, it just calls the standard constructor EMModule().

> So let's try to make this an array of pointers:
> 
> Modules = new *EMModule[modnum];

Ok, this was my starting point, but the answer from root was:

Error: No symbol EMModule in current scope
FILE:/home/hejny/S/GEANT4/pd/./ana/EMCalo.cc LINE:21
Error: Illegal pointer operation (tovalue)
FILE:/home/hejny/S/GEANT4/pd/./ana/EMCalo.cc LINE:21
Error: type *EMModule not defined
FILE:/home/hejny/S/GEANT4/pd/./ana/EMCalo.cc LINE:21
*** Interpreter error recovered ***

> >    Modules[Nn] = EMModule(x,y,z,size);
> 
> Since Modules[Nn] are pointers, do:

Using your declaration they are pointers, but in my framework these
are the objects. 

> Modules[Nn] = new EMModule(x,y,z,size);
>
> [...]
> 
> There are of course also other possible solutions to you question/problem.
> You might use a fixed size array of pointers or consider using a linked
> list of EMModules. Whatever suits you best...

Yes and for the beginning a simple array of EMModule objects should
do it.

Best regards,
Volker

-- 
Volker Hejny                    Tel: 02461/616853                      ** 
Institut f. Kernphysik          Fax: 02461/613930                     **
---------------------------------------------------------------- **  ** ---  
Forschungszentrum Juelich GmbH, D-52425 Juelich                    **



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:38 MET