*I have very little skill in c++. I'm a 17 year old programmer attempting to learn c++.
I am attempting to make a fun project to help me learn c++. This piece of code is some of that result. I am creating a derived class from an equipment base class called Weapon_definition. Within it I want to take the variables from my base class into this class and give them new values when a certain weapon is called. So if shortsword is called then the weapon class object changes its values. This weapon class object is then called in another function for the explicit purpose of copying its values somewhere else. A inventory system pretty much is what this all is. The question itself though is this, is there a better or simpler way to write this? I wrote it this way with the idea that i could forever extend it and it wouldn't take much code to add or remove pieces. New sections like equipable jewelry or armor i could make with a new extern class object and class.
Header File
#ifndef EQUIPMENT_H
#define EQUIPMENT_H
#include <string>
class Equipment_definition{
public:
int value;
int growth;
std::string Tag;
std::string Title;
};
class Weapon_definition: public Equipment_definition{
public:
static void Short_Sword();
static void Long_Sword();
};
extern Weapon_definition Weapon;
#endif
CPP File
#include "Equipment.h"
Weapon_definition Weapon;
void Weapon_definition::Short_Sword(){
Weapon.Title = "Shortsword";
Weapon.Tag = "[Light Weapon]";
Weapon.value = 2;
Weapon.growth = 1;
}
void Weapon_definition::Long_Sword(){
Weapon.Title = "Longsword";
Weapon.Tag = "[Heavy Weapon]";
Weapon.value = 5;
Weapon.growth = 0;
}