Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>While the other answers here are certainly technically correct, whenever I come across a situation like this I see it as pointing out a potential flaw in my design. What you have is <strong>cyclic dependencies</strong>, like so:</p> <p><img src="https://i.stack.imgur.com/PedX1.png" alt="enter image description here"></p> <p>This isn't just a problem for your implementation, it means that there is too much <a href="http://en.wikipedia.org/wiki/Coupling_%28computer_programming%29" rel="nofollow noreferrer">coupling</a> between classes, or, conversely, too little information hiding. This means that you can't design the <code>Player</code> independently of the <code>Game</code>, for example.</p> <p>So if possible, I'd prefer a situation like this, where the <code>Game</code>, as the controller delegates work out to other classes.</p> <p><img src="https://i.stack.imgur.com/Nkkee.png" alt="enter image description here"></p> <p>One way to do this is for the <code>Game</code> to pass references to its own properties as and when the <code>Player</code> needs them.</p> <p>For example have <code>collision</code> take a <code>bots</code> parameter rather than the `Game</p> <pre><code>bool collision(const std::vector&lt;Bot&amp;&gt; bots) { // note pass objects by const ref is usu preferred in C++ to pass by value for (Bot bot: g.bots) ... } </code></pre> <p>(Note in a more sophisticated approach, it could pass interfaces, i.e. abstract base classes, onto itself). </p> <p>If all else fails, you can go back to using a forward declaration.</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.
    3. 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