title: Cannot cast from derived class to base class
body: <p>I cant solve it. I have two classes:</p>
  
  <p><strong>Spatial.h:</strong></p>
  
  <pre><code>namespace graphics {
  
  class Scene;
  class Node;
  /**
   * Spatial is the basic object that builds the scene. Every class that happens to be in the scene is a spatial
   * 
   */
  class Spatial {
  
  public:
  
      /** A spatial must be renderable */
      virtual void render() = 0;
  
      /** Get the scene that the spatial belongs to*/
      Scene* getScene();
  
      /** Set the parent of this spatial to node or to null */
      virtual void setParent(Node* parent) ;
  
  
  protected:
      /** The scene that the spatial belongs to */
      Scene* scene;
  
      /** The parent element of the spatial */
      Spatial* parent;
  
  
  private:
  
  
  };
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Spatial.cpp:</strong></p>
  
  <pre><code>namespace graphics {
  
      Scene* Spatial::getScene() {
          return this-&gt;scene;
      }
  
      void Spatial::setParent(Node* parent) {
          this-&gt;parent = parent; // ERROR: cannot convert 'graphics::Node*' to 'graphics::Spatial*' in assignment
  
          printf("set parent from spatial");
      }
  }
  </code></pre>
  
  <p><strong>Node.cpp:</strong></p>
  
  <pre><code>namespace graphics {
  
      /**
       * Render the children elements of the node
       */
      void Node::render() {
          for (int i = 0 ; i &lt; children.size(); i++) {
              Spatial* child = children.at(i);
              child-&gt;render();
          }
      }
  
      void Node::addChild(Spatial* spatial) {
          children.push_back(spatial);
          spatial-&gt;setParent(this);
      }
  
      void Node::setParent(Spatial* parent) {
          printf("setparent from node"); 
      }
  
  }
  </code></pre>
  
  <p><strong>Node.h</strong></p>
  
  <pre><code>namespace graphics {
  
      using namespace std;
  
      /** 
       * Node contains different spatial elements which can be rendered from inside of it 
       * If node contains other nodes, then the rendering process is said to recursive:
       * - first element to be drawn in this case is the deepest drawable spatial
       */
      class Node : public Spatial {
      public:
          Node();
          Node(const Node&amp; orig);
  
          /** Render all childrens of the node within a given scene */
          virtual void render();
  
          /** Add a child to this node*/
          void addChild(Spatial* spatial);
  
          /** temporrar y*/
          virtual void setParent(Spatial* parent);
  
          virtual ~Node();
  
      protected:
  
          /** All the children elements of the Node */
          vector&lt;Spatial*&gt; children;
  
  
      private:
  
      };
  }
  </code></pre>
  
  <p>At compile time I got the error:</p>
  
  <blockquote>
    <p>cannot convert 'graphics::Node*' to 'graphics::Spatial*' in
    assignment ....</p>
  </blockquote>
  
  <p>Why? I'm assigning a derived class pointer to base class pointer. Elsewhere it works. What's wrong with that?</p>