error: no match for 'operator='

I am trying to compile sample code but code show errors

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
   #include<iostream> 
using namespace std; 

class base{
   public:
      virtual void funct(){ 
      cout<<"This is a base class's funct()";
      }
};

class derived1 : public base{
   public:
     void funct(){  
class
     cout<<"This is a derived1 class's funct()";
     }
};
int main()
{
  base *p, b;
  derived1 d1;
  *p = &b;

  p->funct(); //call to base class funct().
  *p=&d1;

  return 0;
}


test.cpp:21:9: error: no match for 'operator=' (operand types are 'base' and 'base*')
*p = &b;

What's the error and how to remove errors ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream> 

using namespace std; 

class base
{
    public:
   virtual void funct()
   { 
      cout<<"This is a base class's funct()";
      }
};

class derived1 : public base{
   public:
     void funct(){  
         cout << "This is a derived1 class's funct()";
     }
};

int main()
{
  base *p, b;
  derived1 d1;
  p = &b;

  p->funct(); //call to base class funct().
  p=&d1;

  return 0;
}
Topic archived. No new replies allowed.