A a;
B b;
a=b;
这个里面的=应该如何重载?
源代码如下:
#include
#include "board.h"
#include "smart.h"
#include "dumb.h"
#include "human.h"
#include "game.h"
using namespace std;
// main program to test game object
int main(void)
{
game g;
smart s1(1),s2(2);
dumb d1(1),d2(2);
human h1(1),h2(2);
char s[100];
player *p1,*p2;
cout << "Player 1 ? (h,s or d)";
cin >> s;
switch(s[0])
{
case 'h' : p1 = &h1; break;
case 's' : p1 = &s1; break;
case 'd' : p1 = &d1; break;
default :
p1 = &h1;
}
cout << "Player 2 ? (h,s or d)";
cin >> s;
switch(s[0])
{
case 'h' : p2 = &h2; break;
case 's' : p2 = &s2; break;
case 'd' : p2 = &d2; break;
default :
p2 = &h2;
}
int result=g.play(p1,p2);
if (result==1)
{
cout << "Player 1 has won." << endl;
}
else if (result==2)
{
cout << "Player 2 has won." << endl;
}
else
{
cout << "Tie game." << endl;
}
return(0);
}
我得player类中的赋值操作符是这样重载的
player player::operator = (const human *h)
{
this ->kind = h ->kind;
return *this;
}
player player::operator = (const smart *s)
{
this ->kind = s ->kind;
return *this;
}
player player::operator = (const dumb *d)
{
this ->kind = d ->kind;
return *this;
}
可是运行的时候依然报错