title: C++: const volatile methods
body: <p>I'm having a brain cramp:</p>
  
  <pre><code>struct MyStruct
  {
      int x;
  
      ...
  
      inline int getX1() const { return x; }
      inline int getX2() const volatile { return x; }
  };
  
  volatile MyStruct myStruct;
  </code></pre>
  
  <p>I understand that the compiler will let me call myStruct.getX2() and won't let me call <code>myStruct.getX1()</code>, because methods called on volatile structs/classes must have the <code>volatile</code> qualifier on those methods.</p>
  
  <p>Here's my question: If I create such a class, and I publish it for use by other software routines, what are the reasons I would add or not add a volatile qualifier on a method?</p>
  
  <p>Is it because a method tagged <code>volatile</code> tells the compiler not to assume any of its members are not <code>volatile</code>, for optimization purposes, whereas if a method is not tagged <code>volatile</code>, then any members not tagged <code>volatile</code> can be optimized?</p>