title: Sharing function between classes
body: <p>I have three classes which each store their own array of double values. To populate the arrays I use a fairly complex function, lets say <code>foo()</code>, which takes in several parameters and calculates the appropriate values for the array.</p>
  
  <p>Each of my three classes uses the same function with only minor adjustments (i.e. the input parameters vary slightly). Each of the classes is actually quite similar although they each perform separate logic when retrieving the values of the array.</p>
  
  <p>So I am wondering how should I 'share' the function so that all classes can use it, without having to duplicate the code?</p>
  
  <p>I was thinking of creating a base class which contained the function <code>foo()</code> and a virtual <code>get()</code> method. My three classes could then inherit this base class. Alternatively, I was also thinking perhaps a global function was the way to go? maybe putting the function into a namespace?</p>