title: C++ - Copying of objects of derived class into objects of base class
body: <p>We can not copy a derived object into an object of the base class due to the restrictions of the overloading operator <code>=</code>. Then, why can we copy the address of a derived object into the pointer of a base class ? Shouldn't it be the other way around because the derived object is of larger size that the base class object. In fact, when I tried it, I got an error which said that <code>the conversion of a base object to the derived object is not allowed</code>. Can you please tell me why? I am unable to find anything relevant information on the internet.
  The code is as follows:-</p>
  
  <pre><code>#include&lt;string&gt;
  #include&lt;vector&gt;
  #include&lt;iostream&gt;
  using namespace std;
  class employee
  {
      protected:
          string name;
          double pay;
      public:
          employee(string ename,double payRate)
          {
              name = ename;
              pay = payRate;
          }
          virtual double GrossPay(int days)
          {
              return pay*days;
          }
          virtual string getName()
          {
              return name;
          }
  };
  class manager:public employee
  {
      private:
          bool salaried;
      public:
          manager(string ename,double payRate,bool isSalaried):employee(ename,payRate)
          {
              salaried = isSalaried;
          }
          virtual double GrossPay(int days)
          {
              if(salaried)
                  return pay;
              else
                  return pay*days;
          }
  };
  int main(void)
  {
      employee* emp2;
      employee emp3("Bill",350);
      manager mgr3("Alice",200,true);
      emp2 = &amp;emp3;
      cout&lt;&lt;emp2-&gt;getName()&lt;&lt;" earns "&lt;&lt;emp2-&gt;GrossPay(40)&lt;&lt;endl;
      emp2 = &amp;mgr3;
      cout&lt;&lt;emp2-&gt;getName()&lt;&lt;" earns "&lt;&lt;emp2-&gt;GrossPay(40)&lt;&lt;endl; // The code works till here
      //The problematic part starts from here:- 
      manager* mgr6;                                          
      employee emp5("NewBill",300);
      mgr6 = &amp;emp5;
      cout&lt;&lt;mgr6-&gt;getName()&lt;&lt;" earns "&lt;&lt;mgr6-&gt;GrossPay(40)&lt;&lt;endl;
      return 0;
  }
  </code></pre>
  
  <p>Note: The error that I showed is the simplified of what the compiler actually displayed.</p>