I'd like to have a class (atoms), where each instance maintains a list of other instances as a data member (a list of bonded atoms). Is this possible? I just tried writing it up as if it were and I got an error in the constructor.
Printable View
I'd like to have a class (atoms), where each instance maintains a list of other instances as a data member (a list of bonded atoms). Is this possible? I just tried writing it up as if it were and I got an error in the constructor.
Possible, sure, but probably not practical. Any reason you don't want to use a container class?
You may need to make a list of pointers to the other bonded atoms. Or indexes.
This is the old "How do I design a graph class" problem. I've seen a few generic attempts at it, but rarely good ones. You pretty much just have to design what you need each time.
Code:class Atom{
vector<Atom *> Bonded;
}