@hyeon
Some ideas about the code:
Try to avoid having global variables. One idea is to collect them all into their own namespace.
It seems you are using
new
purely to obtain a pointer. Instead, use a std::vector, it does it's own memory management, puts it's data on the heap and makes things easier all round.
Use
nullptr
instead of
NULL
.
nullptr
was invented to get around the problems of using 0 as a pointer.
You have duplicated code, I agree with
Enoizat the classes and their member functions look to be all the same, they only differ in their names. Why is there a need to have any derived classes at all?
Putting that idea another way:
-mesons have 2 quarks.
-baryons have 3 quarks.
-pentaquarks have 5 quarks. |
mesons, baryons, and pentaquarks only differ in the number of quarks they have.
Another thing, it's not a good idea to have protected member data, it's just as bad as public data. It's better to have private data, then functions to manipulate it, though don't fall into the trap of blindly writing get / set functions for each member variable.
If you are going to redefine functions in a derived classes, consider using the
override
keyword.
It is still worthwhile at this late stage,
to see the full text of the assignment verbatim, then we can decide whether you have taken the correct approach, or the whole intent of the assignment is flawed.
Pedantically, there is no need for void here:
int main(void)
It has never been a requirement in C++ to specify
void
when there are no function parameters. It is more a left over from the C language.