S
shadow_x
Unregistered / Unconfirmed
GUEST, unregistred user!
TStringQueue= class(TQueue)
function Push(AString: string): TObject;
function Pop: string;
function Peek: string;
end;
function TStringQueue.Peek: string;
begin
Result := string(inherited Peek);
end;
function TStringQueue.Pop: string;
begin
Result := string(inherited Pop);
end;
function TStringQueue.Push(AString: string): TObject;
begin
Result := TObject(inherited Push( AString ));
end;
=========================================
qs:TStringQueue;
str:String;
qs:=TStringQueue.create;
qs.push('sdfsd');
showmessage(qs.pop);//不报错,正确运行
//-----
str:='sdfsd';
qs:=TStringQueue.create;
qs.push(str);
showmessage(qs.pop);//报错,是指针错误。
为什么?
function Push(AString: string): TObject;
function Pop: string;
function Peek: string;
end;
function TStringQueue.Peek: string;
begin
Result := string(inherited Peek);
end;
function TStringQueue.Pop: string;
begin
Result := string(inherited Pop);
end;
function TStringQueue.Push(AString: string): TObject;
begin
Result := TObject(inherited Push( AString ));
end;
=========================================
qs:TStringQueue;
str:String;
qs:=TStringQueue.create;
qs.push('sdfsd');
showmessage(qs.pop);//不报错,正确运行
//-----
str:='sdfsd';
qs:=TStringQueue.create;
qs.push(str);
showmessage(qs.pop);//报错,是指针错误。
为什么?