Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Nowhere in your code I see numbers <code>10</code> and <code>15</code>. How do you expect the program to know that specific weapon's damage is supposed to be <code>10</code> or <code>15</code>?</p> <p>According to your code, class <code>Weapon</code> has a constructor that accepts the weapon's damage value. But you never use this constructor. Instead, you seem to be constructing <code>m_weapon</code> members using the default constructor of <code>Weapon</code> class, which simply leaves garbage in <code>m_damage</code> field.</p> <p>You have to develop a way to perform a meaningful initialization of your <code>m_weapon</code> objects. At this point you seem to be hoping that the compiler somehow telepathically figures out the damage values for various weapon objects. Compilers cannot do that.</p> <p><strong>EDIT:</strong> What you do in your constructors is just construct a <em>local</em> <code>m_weapon</code> object, which has absolutely no relation to member <code>m_weapon</code> object. Your member <code>m_weapon</code> objects remain uninitialized (i.e. default initialized with garbage in <code>m_damage</code>). It is not possible to perform initialization of member subobject from a constructor body. Member subobjects can only be initialized from constructor initializer list (read about it in your C++ book or do a search). On top of that, you are only allowed to initialize <em>immediate</em> members of the class, meaning that <code>m_weapon</code> can only be initialized from <code>Character</code>'s constructor. It is not possible to do it from <code>Warrior</code>'s or <code>Wizard</code>'s constructor.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload