title: Constructors with functions as arguments in C++
body: <p>I got some objects which variables rely on different functions. To put it in different words: There are multiple types of functions on which the variables in the object rely, but there should be multiple objects with same of these functions. For more clearance I tried to give an example (which does not work).</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  class A
  {
    double size;
  
    A( double (*f)() )
    {
      size = (*f)();
    };
  };
  
  double fun1()
  {
    return 42.0;
  }
  
  
  int main()
  {
    A a = A( &amp;fun1() );
  
    std::cout &lt;&lt; a.size &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>This is of course a minimal example. The variable size depends on a certain function which should be passed as an argument to the class. Imagine <code>fun1</code> and <code>fun2</code> as different kinds of random number generators.</p>
  
  <p>I think that the ideomatic way in C++ would be a class which holds the variable and the classes inherited from it are modified by that function that differs the objects (please correct me if I'm wrong with this assumption). But my question is:</p>
  
  <p>Is there any possibility to implement some kind of higher-order constructor? If so, an example would be nice.</p>
  
  <p>p.s.: If I used some technical terms wrong, I'd be glad to be corrected.</p>