title: structure vs class
body: <p>Today, I was curious to find some of differences between a structure and a class, in C++. So, I found some of the differences:</p>
  
  <ol>
  <li>In a structure, by default members are public while private in class.    </li>
  <li>Inheritance in case of a structure is public by default, while private in case of class.</li>
  <li>Classes can take part in templates, while structures cannot.</li>
  </ol>
  
  <p>click here to see that a <strong>struct</strong> cannot be used in place of <strong>class</strong> in case of <strong>template.</strong>
  <a href="http://ideone.com/p5G57">http://ideone.com/p5G57</a></p>
  
  <pre><code>template&lt;struct T&gt; void fun(T i)
  {
      cout&lt;&lt;i&lt;&lt;endl;
  }
  
  int main()
  {
      int i=10;
      fun&lt;int&gt;(i);
      return 0;
  }
  </code></pre>
  
  <p>It gives the errors:</p>
  
  <pre><code>prog.cpp:4: error: ‘struct T’ is not a valid type for a template constant parameter
  prog.cpp: In function ‘void fun(T)’:
  prog.cpp:4: error: ‘i’ has incomplete type
  prog.cpp:4: error: forward declaration of ‘struct T’
  prog.cpp: In function ‘int main()’:
  prog.cpp:12: error: no matching function for call to ‘fun(int&amp;)’
  </code></pre>
  
  <p>However, if <strong>struct</strong> is replaced with <strong>class</strong>, it works perfectly. see here: <a href="http://ideone.com/K8bFn">http://ideone.com/K8bFn</a></p>
  
  <p>Apart from these above differences, when I replace <code>class</code> with <code>struct</code> in my code, the code works perfectly without making any further changes.</p>
  
  <p>Now, I want to know, <strong>are there more differences, that I am missing and I should know?</strong> </p>