title: C++: Why can a statically created variable by passed to a function expecting a reference?
body: <p>I've been programming in C++ for a while but certainly wouldn't call myself an expert. This question isn't being asked to solve a practical problem that I have, it's more about understanding what C++ is doing.</p>
  
  <p>Imagine I have a function that expects a single paramater:</p>
  
  <pre><code>void doSomething(SomeClass&amp; ref)
  {
      // do something interesting
  }
  </code></pre>
  
  <p>(Note: the parameter is a reference to SomeClass) Then I call the function like this:</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
      SomeClass a;
      doSomething(a);
  }
  </code></pre>
  
  <p>Why is this legal C++? The function is expecting a reference to SomeClass, but I'm passing it a statically allocated variable of type SomeClass. A reference is like a pointer no? If we were to replace the reference with a pointer the compiler complains. Why is the reference different to a pointer in this way, what's going on behind the scenes?</p>
  
  <p>Sorry if this is a stupid question, it's just been buggin me!</p>