title: Why is this static_cast not allowed?
body: <p>I have an object of class A that I want to allocate on a custom stack object.  To do this, I simply move the stack pointer as many bytes as the object is in size and return its previous value:</p>
  
  <pre><code>class A : public B {}; //B is from a precompiled library
  
  class stack {
  public:
      stack(void): _top(&amp;_storage[0]) {}
  
      template &lt;typename T&gt;
      inline T* push(void) {
          T* ptr = static_cast&lt;T*&gt;(_top);
  
          _top += sizeof(T);
  
          return ptr;
      }
  
      //...
  
  private:
      char _storage[1024];
      char* _top;
  };
  
  stack _stack;
  
  int main(int argc, char** argv) {
      A* a = _stack.push&lt;A&gt;(); //ignore the lack of a constructor call
  
      return 0;
  }
  </code></pre>
  
  <p>Visual C++ simply tells me that static_cast cannot convert from char* to A*.  A regular C style cast does not give me this error, but I'd rather be more explicit and avoid a dynamic cast (A inherits from another class, but does not contribute to the vtable it doesn't have).  Is there any difference between the two in this case?</p>