title: Using a class in a header file without access to its definition?
body: <p>This is excerpt from <a href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Header_File_Dependencies" rel="nofollow">google's c++ coding guidelines</a>.</p>
  
  <blockquote>
    <p>How can we use a class Foo in a header
    file without access to its definition?</p>
    
    <ul>
    <li>We can declare data members of type Foo* or Foo&amp;. </li>
    <li>We can declare (but not define) functions with arguments, and/or
    return values, of type Foo. (One
    exception is if an argument Foo or
    const Foo&amp; has a non-explicit,
    one-argument constructor, in which
    case we need the full definition to
    support automatic type conversion.)</li>
    <li>We can declare static data members of type Foo. This is because static
    data members are defined outside the
    class definition.</li>
    </ul>
  </blockquote>
  
  <p>What I'm curious about is exception in the second bullet. Why is this so? Why is the full definition needed if we want to support automatic type conversion?</p>
  
  <p>My guess is that compiler needs the full definition of the destination type because of the temporary object that is created in the implicit conversion. Am I guessing correctly? Is there more to it?</p>
  
  <p>EDIT:</p>
  
  <p>As I see it, the exception in the guideline is addressed to situation like this:</p>
  
  <pre><code>class A
  {
      public:
          A( int );
  };
  
  class B
  {
      public:
          B( A const &amp;a );
  };
  
  int main()
  {
      B b(2);
  }
  </code></pre>
  
  <p>Here we have only one user-defined implicit conversion (from int to A), and call to constructor that accepts A const &amp;. Only thing that makes sense in this exception is to support direct conversion from e.g. int to A, and then to B via constructor that accepts A const &amp;, allowing client code to use this conversion chain without need to explicitly include header file where A class is declared.</p>