DeleteDD();
wpnList.clear(); // clear vectors and delete
armorList.clear(); // dynamic data
skillList.clear();
if (c.name) {
name = newchar[strlen(c.name) + 1]; // if name exists copy
strcpy(name, c.name);
}
for (int i = 0; i < ABILITY_MAX; i++) // copy new abilities
abilities[i] = c.abilities[i];
if (c.currWpn)
currWpn = new WpnClass(c.ReturnCurrWpn());
if (c.currArmor)
currArmor = new ArmorClass(c.ReturnCurrArmor());
hp = c.hp;
wpnList = c.wpnList;
armorList = c.armorList;
skillList = c.skillList;
Now Humanoid inherits Creature and contains no dynamic data but I am required to provide a copy constructor and assignment operator so my question is what should it contain?
Do I have to call Creature's copy constructor and then copy every encapsulated data member manually?
This is how I am guessing it would like:
1 2 3 4 5 6 7
Humanoid::Humanoid(const Humanoid& h) : Creature(const Creature& c) {
copy all Humanoid data manually even though it's non-pointer data
}
new WpnClass(c.ReturnCurrWpn());vector<WpnClass> wpnList;
I'm confused. ¿What is the purpose of wpnList? I thought it will hold the weapons in your inventary, put in that case ¿why are you creating a new one?
If you are using polymorphism you are losing it in the copy (and the container makes no sense).
If you aren't using it, then ¿why dynamic allocation?
We do not think an empty weapon should be created, so we made the default constructor protected so that we will always create a weapon or armor by passing it a name as a string to create it.
ReturnCurrArmor( ) and ReturnCurrWpn( ) return the name of them as a string so you can use it to create a new instance.
Since you can't call the default constructor we made CurrWpn and CurrArmor pointers so that we can allocate them dynamically when we get an actual string to construct from. So a creature will have a current weapon and armor as well as a wpn and armor list.
And we won't use polymorphism until we add on to this program. It is sorely needed.
This is all for the OOP class for my CS degree so we are doing most things just to learn them. We learned that by making default constructor protected or private the client is forced to use a parameterized constructor and that by doing that we as the programmers must also rely on using dynamic data.
And yes, I most definitely prefer C++ strings but my Prof is old school and wants us to be familiar with C-style strings. If I had my way I would be doing all of this in C# using visual studio. lol
I do not plan on coding in C++ for a living. I have much more fun doing asp.net stuff in C# or VB and whatever will take its place.
But I can definitely understand why they teach us C++. If you can code in C++, you can code in any other high level language.