Class instance of another class instance?

+4 Earl Hudson · November 6, 2015
  Okay, let's see if I have this right. If I decided to write an RPG, and I want to have class Player, and class Weapon... 2 classes
I can create an instance of Player that has the instance of weapon inside it? That sounds pretty cool.

But it does raise some questions...
1st, obviously how do you do this? 

2nd Let's say I want to calculate damage from the weapon, how do I access it? 
Do I have to go through Player :: Weapon.damage ?? 
Would I have to write a method in Player to access a method of weapon?

What are the advantages and dis - advantages of doing this?

Post a Reply


Oldest  Newest  Rating
0 Earl Hudson · November 9, 2015
No. Haven't considered it yet... But I will now.  You're awesome...  thank you.
  • 1



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator