title: C++: Initializing class member variable with reference to another class member variable?
body: <p>I am attempting to make a class in c++ called to store values for a number of parameters that are organized as member variables of class 'Planet' and class 'Satellite', which I want to initialize with a reference to an instance of 'Planet'. Here I provide an example where I have a 'PlanetCatalog' class with 
   member variables 'Planet neptune' and a 'Satellite triton'.</p>
  
  <pre><code>class Planet {
      public:
  
      double a;
  
      Planet() {}
  
      void setParams(  const double a_) {
          a = a_;
      }
  };
  
  
  class Satellite {
      public:
  
      double b;
  
      Planet &amp; planet;
      Satellite( Planet &amp; planet_):planet(planet_) { }
  
      void setParams(const double b_) {
          b = b_;
      }
  }; 
  
  class PlanetCatalog {
  
      public:
  
      Planet neptune;
      Satellite triton(neptune);
  
      void setAll() {
          neptune.setParams(1.);
          triton.setParams(2.);
      }
  
  };
  </code></pre>
  
  <p>However, upon compiling I encounter the error. </p>
  
  <pre><code>error: unknown type name 'neptune' 
      Satellite triton(neptune);
  </code></pre>
  
  <p>Is it possible to have the Planet and Satellite stored as variables of the same class as I have done here. If not, could someone suggest a better way of organizing this functionality in c++?</p>