[Tree-hh] Help needed with a copy constructor.

Kasper Peeters kasper.peeters at aei.mpg.de
Thu Dec 3 20:19:17 GMT 2009


Hi Stefan,

> class Genome
> {
> private:
>     int m_Identity, m_Generation;
>     tree<string> *tr;  //Tree root

First of all, why don't you just put the tree in directly? I.e.

   tree<string> tr;

Then copy constructing will be automatic.

If you cannot do this (perhaps you want to share the same tree among
multiple Genome objects), then you can copy-construct a tree with

   tr = new tree<string>( *othertree );

where 'othertree' is a pointer to a tree<string>. This will make a
copy of the other tree, and store that copy in the location pointed to
by 'tr'.

Hope this helps.

Cheers,
Kasper



More information about the Tree-hh mailing list