Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There does not appear to be anything wrong with the code you've presented. </p> <p>While the <code>try-catch</code> construct you're using might not be something I would do, there is nothing wrong with it as far as I can tell. The C++03 and C++11 Standards both guarantee that <code>at</code> will <code>throw</code> an <code>std::out_of_range</code> if the element does not exist.</p> <p>You need to look elsewhere for the bug. One thing that piques my interest is the fact that you are dynamically allocating the <code>vector</code>. No reasoning for this is presented, but since there doesn't appear to be anything wrong with how you're using the <code>vector</code> <em>assuming it exists</em>, a likely scenario is that the <code>vector</code> is corrupted, was deleted, or something else is wrong with your dynamic memory management. If you can get by without using dynamic allocation, I would strongly recommend it. If you can't get by without dynamic allocation, then at least use a smart pointer instead of raw pointers.</p> <p>Another place to look is the constructors for <code>player</code>, in particular the copy constructor. Since <code>push_back</code> is going to create a copy of the element being added, if there's nothing wrong with the <code>vector</code> itself, the problem might be in the copy constructor.</p> <p>Write a copy constructor for <code>player</code>, like this:</p> <pre><code>player (const player&amp; rhs) : posX (rhs.posX), mapId (rhs.mapId), plyId (rhs.plyId), playerModel (rhs.playerModel) { } </code></pre> <p>Set a breakpoint on the first line of the initialization list. Does it hit? Step in to each member's constructor. Do they crash?</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. This table or related slice is empty.
    1. 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