我试图在这个函数中验证,如果参数T
的类型char*
也是如此,我怎么能实现它,因为在这个实现中它将返回false并且getValue返回类型为{的对象{1}}
T
答案 0 :(得分:0)
如果要为模板类专门化成员函数,则需要专门化整个类。这是一个给你一个想法的最基本的例子。
program NEACardTrick;
{$APPTYPE CONSOLE}
uses
SysUtils,
Math;
type
Tcards = array[1..21] of string;
var
cards: Tcards = ('H A', 'H 2', 'H 3', 'H 4', 'H 5', 'H 6', 'H 7',
'S A', 'S 2', 'S 3', 'S 4', 'S 5', 'S 6', 'S 7',
'D A', 'D 2', 'D 3', 'D 4', 'D 5', 'D 6', 'D 7');
shuffledCards:Tcards;
i,j,y, x: integer;
function get_cards(var cards: array of string): Tcards;
begin
y := 1;
Repeat
Randomize;
x := RandomRange(1,21);
If cards[x] <> 'Done' then
begin
shuffledCards[y] := cards[x];
y := y + 1;
cards[x] := 'Done';
end
Until y >= 21;
result := shuffledCards;
end;
procedure PrintCards(var shuffledCards: Tcards);
var
j: integer;
begin
for j := 1 to 21 do
writeln(shuffledCards[j]);
end;
begin
get_cards(cards);
PrintCards(shuffledCards);
readln;
end.