title: error in C++, within context
body: <p>I received homework to make program without casting using constructors so this is my code, I have two classes:</p>
  
  <pre><code>class Base {
  protected:
      int var;
  public:
      Base(int var = 0);
      Base(const Base&amp;);
      Base&amp; operator=(const Base&amp;);
      virtual ~Base(){};
      virtual void foo();
      void foo() const;
      operator int();
  };
  
  class Derived: public Base {
  public:
      Derived(int var): Base(var){};
      Derived(const Base&amp;);
      Derived&amp;  Derived::operator=(const Base&amp; base);
      ~Derived(){};
      virtual void foo();
  };
  </code></pre>
  
  <p>here two of my functions of Derived:</p>
  
  <pre><code>Derived::Derived(const Base&amp; base){
      if (this != &amp;base){
          var=base.var;
      }
  }
  
  Derived&amp;  Derived::operator=(const Base&amp; base){
      if (this != &amp;base){
          var=base.var;
      }
      return *this;
  }
  </code></pre>
  
  <p>but I have an error <code>within context</code> when I call these rows</p>
  
  <pre><code>Base base(5);
  Base *pderived = new Derived(base);  //this row works perfectly
  Derived derived = *pderived;  // I think the problem is here
  </code></pre>
  
  <p>thanks for any help  </p>