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 - 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
-
-
-
-
-
Why reinvent the wheel?3m 12s
-
(Locked)
Extending classes4m 37s
-
(Locked)
Access control in inheritance4m 1s
-
(Locked)
Overriding and extending functionality2m 11s
-
(Locked)
Multiple inheritance2m 22s
-
(Locked)
Multiple inheritance pitfalls6m 32s
-
(Locked)
Challenge: RPG character system2m 25s
-
(Locked)
Solution: RPG character system1m 35s
-
-
-
-