Sorry marcel. You are little confused , let me explain the class hierarchy first.
---------------------------------------
---------------------------------------
^ ^ ^ ^
| | | |
| | | |
Molecule | | |
| | |
Atom | |
| |
Bond |
Ring
---------------------------------------
| QObject |
---------------------------------------
^ ^ ^ ^
| | | |
| | | |
Molecule | | |
| | |
Atom | |
| |
Bond |
Ring
To copy to clipboard, switch view to plain text mode
In my senario "Molecule_object" is the parent of "Atom /Bond " objects.
see main.cpp ...
//children of molecule, 3 atoms, 3 bonds
//Atoms
Atom* atom1 = new Atom( molecule );
Atom* atom2 = new Atom( molecule );
Atom* atom3 = new Atom( molecule );
//bonds
Bond* bond1 = new Bond( molecule );
Bond* bond2 = new Bond( molecule );
Bond* bond3 = new Bond( molecule );
//children of molecule, 3 atoms, 3 bonds
//Atoms
Atom* atom1 = new Atom( molecule );
Atom* atom2 = new Atom( molecule );
Atom* atom3 = new Atom( molecule );
//bonds
Bond* bond1 = new Bond( molecule );
Bond* bond2 = new Bond( molecule );
Bond* bond3 = new Bond( molecule );
To copy to clipboard, switch view to plain text mode
And " Molecule_object " has a "Ring" , see the code ..
{
---
---
private :
Ring _ring* ;
}
class Molecule : public QObject
{
---
---
private :
Ring _ring* ;
}
To copy to clipboard, switch view to plain text mode
In main.cpp..
//In Molecule , create a RING [ using function Molecule::createRing( Bond * ) ]
//A ring is a closed polygon [ chemistry term ].
molecule->createRing( bond1 );
molecule->createRing( bond2 );
molecule->createRing( bond3 );
//In Molecule , create a RING [ using function Molecule::createRing( Bond * ) ]
//A ring is a closed polygon [ chemistry term ].
molecule->createRing( bond1 );
molecule->createRing( bond2 );
molecule->createRing( bond3 );
To copy to clipboard, switch view to plain text mode
So "Ring_object " is NOT A CHILD of "Bond_object".
Instead "Ring_Object" is getting created in a "Molecule_object" [ using function Molecule::createRing( Bond * ) ]
see the code..
void Molecule::createRing( Bond* b)
{
if( !_ring )
{
_ring = new Ring( this );
}
_ring->addBond(b);
}
void Molecule::createRing( Bond* b)
{
if( !_ring )
{
_ring = new Ring( this );
}
_ring->addBond(b);
}
To copy to clipboard, switch view to plain text mode
thanks
Bookmarks