Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Classes are useful because they can have methods and state/data</strong>. Generally speaking, if there is any data in your class, it's meaningless that you don't create any objects. However, you can implement a utility class which is composed of public static functions only. In such a case you don't have to create any object.</p> <pre><code>Class CMyHelper { public: static double calculateDistance(CPoint A, CPoint B); static double calculateArea(double length, double width); //... private: // You can even explictly say, I don't want make objects of this class. // You'll get a compile-time error if someone tries. CMyHelper(); CMyHelper(const CMyHelper&amp;); } CPoint A(100, 200); CPoint B(50, 100); //Call static method without instantiation CMyHelper::calculateDistance(A, B); </code></pre> <p><strong>In your case, there is no need to use static class, and friend class as we can see.</strong></p> <p>To me, friend class is the last thing I'll resort to. According to your description, you can make <code>move()</code> be the public method of <code>player</code> class since it's the player who actually "moves" instead of the <code>map</code>. Also, you need make it clear to us what's your <code>map</code> class does.</p> <p><strong>Edit:</strong> You can move coordinate of the player to player class if your map class is simpe enough to remove.</p> <pre><code>Class CPlayer { public: void move() { // moves up, down, left, or right // update m_position } } private: CCoordinate m_position; } </code></pre>
    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