title: C++ static_cast runtime overhead
body: <p>See the code below.</p>
  
  <p>a) Does, in this case (simple inheritance, no virtual members), the static cast in B::df() have any overhead (whatsoever)? I found some conflicting answers to similar questions, that's why I am asking...</p>
  
  <p>b) I was thinking about making <code>const M1 * func</code> private in A and introducing a new private field <code>const M2 * func</code> into B to avoid the cast, but it kind of complicates things up and makes use of smart pointers more difficult. Do you see a better way to avoid the cast?</p>
  
  <p><pre><code>
  class M1 {
  public:
      double f() const;
  };</p>
  
  <p>class M2 : public M1 {
  public:
      double df() const;
  };</p>
  
  <p>class A {
  protected:
      const M1 * func;
  public:
      A(const M1 * p);
      ~A();
      double f() const;
  };</p>
  
  <p>class B : public A {
  public:
      B(const M2 * p);
      double df() const;
  };
  </pre></code></p>
  
  <p><pre><code>
  double M1::f() const { return 1973.0; }
  double M2::df() const { return 0.0; }</p>
  
  <p>A::~A() { delete func; }
  A::A(const M1 * p) : func(p) {}
  double A::f() const { return func->f(); }</p>
  
  <p>B::B(const M2 * p) : A(p) {}
  double B::df() const { return static_cast&lt;const M2*&gt;(func)->df(); }
  </pre></code></p>