D
demon_yx
Unregistered / Unconfirmed
GUEST, unregistred user!
type
Tperson=class
public
procedure draw();virtual;
end;
Tman=class(Tperson)
public
procedure draw();overload;
end;
Twoman=class(Tperson)
public
procedure draw();override;
end;
Tform=class(Tform)
public
a:Tman;
b:Twoman;
end;
procedure Tperson.draw();
begin
showmessage('person');
end;
procedure Twoman.draw();
begin
showmessage('woman');
end;
procedure Tman.draw();
begin
showmessage('man');
end;
procedure TForm1.Button2Click(Sender: TObject);
//var
// b:Twoman;
begin
// b:=Twoman.creat;
a.draw <---正确!
b.draw 〈---错误!
end
这样用覆盖是错误的,为什么?
Tperson=class
public
procedure draw();virtual;
end;
Tman=class(Tperson)
public
procedure draw();overload;
end;
Twoman=class(Tperson)
public
procedure draw();override;
end;
Tform=class(Tform)
public
a:Tman;
b:Twoman;
end;
procedure Tperson.draw();
begin
showmessage('person');
end;
procedure Twoman.draw();
begin
showmessage('woman');
end;
procedure Tman.draw();
begin
showmessage('man');
end;
procedure TForm1.Button2Click(Sender: TObject);
//var
// b:Twoman;
begin
// b:=Twoman.creat;
a.draw <---正确!
b.draw 〈---错误!
end
这样用覆盖是错误的,为什么?