Re: [ROOT] root i/o and default ctor

From: Ingo Strauch (strauch@mail.desy.de)
Date: Mon Nov 26 2001 - 20:21:57 MET


Hi joe!

> i dont get the point with NOT allocating space for
> embedded pointers in the ctor.

When reading in objects from file, ROOT first calls the default ctor and
then allocates and fills memory for embedded pointers. If you"ve already
allocated memory in the default ctor, this memory is lost since you
don't have a way to access it properly.


> Its annoying if one cant do it at the ctor since EVERY
> function now has to check for a null pointer and
> create it.
> 
> So i guess if my default ctor look somethin like this
> 
> TTest::TTest()
> {
> init();
> }
> 
> and init() is
> 
> fData=new Whatever();
> 
> This is not allowed either !

Correct.


> BTW what IS teh default ctor ?? the FIRST in the h
> file or must i put a //default or so in the code ??

The default ctor simply is the one that takes no parameters. If all
parameters have default values, such a ctor can also be called default
ctor. And then it's a bad idea to try and write a ctor that takes no
parameter.


> What if the user does not call the default and in the
> non default an object will be constructed ???

No problem here as far as I can see...

Cheers,
Ingo

-- 
"What're quantum mechanics?"
"I don't know. People who repair quantums I suppose."
                                     --Rincewind, Terry Pratchett "Eric"



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:09 MET