From the course: Object-Oriented Programming with C++

Unlock this course with a free trial

Join today to access over 24,800 courses taught by industry experts.

Solution: RPG character system

Solution: RPG character system - C++ Tutorial

From the course: Object-Oriented Programming with C++

Solution: RPG character system

(exciting music) - [Instructor] Welcome back. I hope you had fun implementing the Warrior class. Let's look at my solution to see if you did things similarly. First, here's how I made Warrior inherit from the character class. Notice the public key word before Character. This is crucial because it maintains the access levels of the base class. Next, I added our equipment member to manage the inventory. When using composition here instead of inheriting from equipment the Warrior class has an equipment object as a member. Now let's switch to the implementation, for the attack method I included the Warrior strength bonus like this. Warrior is a char class of character, thus, it can access base damage and name directly because these are protected members of the base class. The display Stats method shows both basic character info and Warrior specific details. I used the base class functionality by calling character display Stats before adding my own logs. Finally, the add item method simply…

Contents