title: Initialise reference variable as a class member
body: <p>I am trying to convert a function from a camera SDK I am using to a class, so I can call the different parts of the function separately (initialisation, capture image, clean up). A problem I am having is that some variables in the function are defined as:</p>
  
  <pre><code>type&amp; var = type::init();
  </code></pre>
  
  <p>This doesn't work when I do:</p>
  
  <pre><code>class myClass
  {
  private:
  type&amp; var;
  };
  </code></pre>
  
  <p>I've tried to change:</p>
  
  <pre><code>type&amp; var;
  </code></pre>
  
  <p>To:</p>
  
  <pre><code>type* var;
  </code></pre>
  
  <p>And that worked fine when I had everything in a single function, but when I try to break it up into separate functions in a class, the code compiles but doesn't run. Is there something fundamentally wrong with my code?</p>
  
  <p>EDIT:
  The code is from Basler's SDK, the original code is:</p>
  
  <pre><code>Pylon::CTlFactory&amp; TlFactory = Pylon::CTlFactory::GetInstance();
  </code></pre>
  
  <p>In the header file:</p>
  
  <pre><code>Pylon::CTlFactory *TlFactory;
  </code></pre>
  
  <p>And the cpp file:</p>
  
  <pre><code>TlFactory = &amp;Pylon::CTlFactory::GetInstance();
  </code></pre>
  
  <p>As mentioned, when all the code is in a single function, it compiles and runs fine, it's only when I break it up into class functions that I have problems...</p>