Hm, what exactly is different about the
behavior of the different elements (not the
data, like mass, but the behavior)? If there isn't a difference, subclassing probably isn't necessary at all. If there is, is it solely determined by the data? If so, why can't external objects just read the data and determine the proper course of action?
One example of this situation I've seen on these forums before is an RPG with character classes. Most people instantly code a base class from which they derive different game classes (bard, warrior, mage, etc.). However, this is often viewed as an abuse of inheritance, since the
data (i.e., stats) may be different, but the
behavior is essentially the same.
Also, I'm assuming that the data for each atom is static and does not change at runtime (this makes sense, unless you're planning on simulating electrons, nuclear reactions, ions and electricity, or some other phenomenon that can alter the state of the atom). In this case, you may want to look into template meta-programming. Using class/struct templates could speed up your code and allow you to do some neat tricks and optimizations. This would probably require a large enumeration though, and could easily lead to code bloat.
enum elements { hydrogen, helium};template<elements E>struct atom { BOOST_STATIC_ASSERT(0 == sizeof(E)); };template<>struct atom<hydrogen> { enum { some_int_data = 0 }; static const float some_float_data = 0.0f;};template<>struct atom<helium> { enum { some_int_data = 0 }; static const float some_float_data = 0.0f;};template<element E>void foo(const atom<E>& bar) { std::cout << bar.some_int_data << std::endl;}
Just an idea. Anyway, I hope something here helps. :-) Good luck!
[Edited by - GenuineXP on January 16, 2009 10:42:09 AM]