c++ - How to approach implenting a class's methods when these methods depend on another class? -


i'm not sure have terminology straight able describe question, here's how i'll describe i'm wondering:

suppose have class a, , second class b uses data in methods

class      {      data1      data2      etc...      }  class b      {      some_data      method1             {            // stuff some_data , a.data1, a.data2            }      method2             {            // other stuff some_data , a.data1, a.data2            }      } 

what i'm curious is, whether generality, considered better like: 1.

class b      {      b(a *a)             {            this->a_ptr = a;            }      *a_ptr       some_data      method1()           {            // stuff a_ptr->data1, a_ptr->data2           }      method2()            {            // other stuff  a_ptr->data1, a_ptr->data2            }      } 

versus

2.

class b      {      some_data      method1(a *a)           {            // stuff a->data1, a->data2           }      method2(a *a)            {            // other stuff  a->data1, a->data2            }      } 

is there consensus approach use? if so, reasons prefer 1 approach on other?

rework inherited mrlister commented, otherwise method 1 has object ownership issues. if that's not possible, use method 2, modified method(a &a) (or method(const &a) if that's intention) clarify object required.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -