title: upcasting from derived to templated base in C++
body: <p>EDIT:</p>
  
  <p>I realized that this code compiles and works:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  template&lt;class Something&gt; class Base {
  public:
      Base() {
  
      }
  
      virtual ~Base() {
      }
  
      virtual void method() = 0;
  };
  
  class Derived: public Base&lt;std::string&gt; {
  public:
      Derived() {
  
      }
  
      virtual ~Derived() {
  
      }
  
      void method() {
      }
  };
  
  template&lt;class Something&gt; class TemplatedClass {
  public:
      void method(Base&lt;Something&gt;* base) {
      }
  };
  
  class SomeClass: public TemplatedClass&lt;std::string&gt; {
  };
  
  int main(int argc, char **argv) {
  
      Derived* d = new Derived();
  
      Base&lt;std::string&gt;* b = d;
      Base&lt;std::string&gt;* b1 = dynamic_cast&lt;Base&lt;std::string&gt;*&gt;(d);
      Base&lt;std::string&gt;* b2 = static_cast&lt;Base&lt;std::string&gt;*&gt;(d);
  
      SomeClass sc;
      sc.method(b);
      sc.method(b1);
      sc.method(b2);
  }
  </code></pre>
  
  <p>Then, I am doing a really big mistake preparing the skeleton or even trying to understand my own code. WHAT a SHAME!!! Sorry... This is a really bad question. It would be better to remove it...</p>
  
  <p>** NO SENSE QUESTION AND CODE BELOW **
  Given this:</p>
  
  <pre><code>template&lt;class Something&gt; class Base
  {
      virtual void method() = 0;
  };
  
  class Derived: public Base&lt;std::string&gt;
  {
      void method() { ... };
  };
  </code></pre>
  
  <p>I want to downcast a pointer of <code>Derived</code> to a pointer of <code>Base</code>. I tried to use <code>dynamic_cast</code> with no success:</p>
  
  <pre><code>...
  Derived* d = new Derived();
  Base* b = dynamic_cast&lt;Base*&gt;(d);
  ...
  </code></pre>
  
  <p>I always got errors during execution.</p>
  
  <p>I don't know if I need downcasting,. I have this situation:</p>
  
  <pre><code>template&lt;class Something&gt; class TemplatedClass
  {
      void method(Base&lt;Something&gt;* base) { ... };
  };
  
  class SomeClass : public TemplatedClass&lt;std::string&gt; { ... };
  </code></pre>
  
  <p>And I want to call (EDITED*):</p>
  
  <pre><code>Derived* d = new Derived();
  
  SomeClass sc;
  sc.method(d);
  </code></pre>
  
  <p>But it gives me an conversion error.</p>
  
  <p>What does I need? Downcasting or what?</p>