title: C++ pointers to class instances
body: <p>I have an (for C++ programmers better than me) simple problem with classes and pointers.
  I thought about posting example code describing my problem but I found it easier to just explain it in words.</p>
  
  <p>Assuming I have three classes:</p>
  
  <ul>
  <li><strong>Class A:</strong> The main class - it contains an instance of both <code>B</code> and <code>C</code>.</li>
  <li><strong>Class B:</strong> This class contains a method that outputs some string, call it <code>Greet()</code>.</li>
  <li><strong>Class C:</strong> This one has a method too, but that method has to call <code>Greet()</code> in the instance of <code>B</code> that is located in class <code>A</code>. Let's name it <code>DoSomethingWithB()</code></li>
  </ul>
  
  <p>So the program starts, in the main function I create an instance of <code>A</code>. <code>A</code>, again, creates instances of <code>B</code> and <code>C</code>. Then, A calls <code>C.DoSomethingWithB();</code>.</p>
  
  <p>And there my problem begins: I can't access <code>B</code> from inside <code>C</code>. </p>
  
  <p>Obviously, I will need to pass a pointer to <code>B</code> to the <code>DoSomethingWithB()</code> function so that I can call <code>B.Greet()</code> from inside <code>C</code></p>
  
  <p>Long explanation, short question: <strong>How do I do this?</strong></p>
  
  <p>Example code incoming:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class B
  {
  public:
      void Greet( )
      {
          cout&lt;&lt;"Hello Pointer!"&lt;&lt;endl;
      }
  };
  
  class C
  {
  public:
      void DoSomethingWithB( )
      {
          // ... b.Greet( ); Won't work obviously
      }
  };
  
  class A
  {
  public:
   B b; // Not caring about visibility or bad class/variable names here
   C c;
   void StartTest( )
   {
        c.DoSomethingWithB( );
   }
  };
  
  int main( )
  {
      A mainInstance;
      mainInstance.StartTest();
  }
  </code></pre>