title: Why am I getting error "reference to struct_tag is ambiguous" with using namespace std?
body: <p>I was trying to write a function with a return type of <em>struct variable.</em> If I use <code>using namespace std;</code> I get an error but if instead use <code>std::</code> the program runs fine. </p>
  
  <p><strong>The erroneous code:</strong></p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  
  struct distance
  {
      int feet;
      int inches;
  };
  distance foo(distance, distance);
  int main()
  {
      distance d1, d2;
      cout &lt;&lt; "Input feet of d1: ";     cin &gt;&gt; d1.feet;
      cout &lt;&lt; "\nInput inches of d1: "; cin &gt;&gt; d1.inches;
      cout &lt;&lt; "\nInput feet of d2: ";   cin &gt;&gt; d2.feet;
      cout &lt;&lt; "\nInput inches of d2: "; cin &gt;&gt; d2.inches;
      distance large = foo(d1, d2);
      cout &lt;&lt; "The larger distance is: " &lt;&lt; large.feet &lt;&lt; "\'-" &lt;&lt; large.inches &lt;&lt; "\"";
  }
  distance foo(distance d1, distance d2)
  {
      float temp1 = d1.feet + d1.inches/12;
      float temp2 = d2.feet + d2.inches/12;
      if(temp1&gt;temp2) return d1;
      else return d2;
  }
  </code></pre>
  
  <p>Error: Reference to <code>distance</code> is ambiguous.</p>
  
  <p><strong>Working code without namespace std:</strong></p>
  
  <pre><code>#include&lt;iostream&gt;
  
  struct distance
  {
      int feet;
      int inches;
  };
  distance foo(distance, distance);
  int main()
  {
      distance d1, d2;
      std::cout &lt;&lt; "Input feet of d1: "; std::cin &gt;&gt; d1.feet;
      std::cout &lt;&lt; "\nInput inches of d1: "; std::cin &gt;&gt; d1.inches;
      std::cout &lt;&lt; "\nInput feet of d2: "; std::cin &gt;&gt; d2.feet;
      std::cout &lt;&lt; "\nInput inches of d2: "; std::cin &gt;&gt; d2.inches;
      distance large = foo(d1, d2);
      std::cout &lt;&lt; "The larger distance is: " &lt;&lt; large.feet &lt;&lt; "\'-" &lt;&lt; large.inches &lt;&lt; "\"";
  }
  distance foo(distance d1, distance d2)
  {
      float temp1 = d1.feet + d1.inches/12;
      float temp2 = d2.feet + d2.inches/12;
      if(temp1&gt;temp2) return d1;
      else return d2;
  }
  </code></pre>
  
  <p>As far as I know namespace std has objects like <code>cout, cin</code> etc. But what does it have to do with structures? Why does <code>using namespace std</code> give error while directly using <code>std::</code> runs the program smoothly?</p>