So for class we have to make a D&D 3.5 game, and for the first assignment I have to generate a Fighter character. The way I have the hierarchy set up in my head is character.cpp and it’s child is classname.cpp where it has some attributes specific to the class since all classes share the same basic things.
Is that a good structure for it? If it’s related we haven’t done STL yet.
Another issue that arose is since my teammate will be making a GUI for the game he may also make a class called character. I thought to resolve this I would make a namespace. But if I make each of the files I make have their class inside namespace d20 in each of their respective headers would all of those namespaces be one and the same? I can’t think of a very good way to word this question.
Here’s my best stab at answering you…
A good inheritance structure is very context specific, but the basic principle is a base class contains data and functions relevant to all the derived classes. Derived classes will contain specific data and functions to itself. In your case there will be a lot of data in the base class ‘character’ like all the character stats and functions that compute outcome based on stats (I’m assuming the rules of the game are generally class independent).
I’m also assuming when you say ‘classname.cpp’ you mean ‘fighter.cpp’, ‘cleric.cpp’, etc. In that case, yes, I would agree with making it structured that way.
STL doesn’t really have a direct impact on coming up with class hierarchies, so I would say no, it’s not related.
As for namespaces, anytime you specify a namespace it will be the same as anywhere else you specify the exact same name (which is what I think you’re asking). You don’t need to do anything special to make it the same namespace other than naming it the same exact thing. A simple example is as follows:
character.h
character.cpp
fighter.h
OR (without the namespace keyword)
Edit: Please note that in the second case the Fighter class is NOT is the namespace d20, it just derives from a class in that namespace.