叮
叮叮当当
Unregistered / Unconfirmed
GUEST, unregistred user!
请教!怎么这么简单的一段程序都不能通过?
var
P: Pointer;
I: Integer;
begin
P := P + I;
end;
编译时报错 "Operator not applicable to this operand type" !
P := P + 1 也不行![]
Inc(P)
倒可以,为什么??
查看 Delphi 中关于 Pointer 类型的说明如下:
The relational operators <, >, <=, and >= can take operands of type PChar (see Relational operators). The following operators also take pointers as operands. For more information about pointers, see Pointers and pointer types.
Operator Operation Operand types Result type Example
+ pointer addition character pointer, integer character pointer P + I
- pointer subtraction character pointer, integer character pointer, integer P - Q
^ pointer dereference pointer base type of pointer P^
= equality pointer Boolean P = Q
<> inequality pointer Boolean P <> Q
The ^ operator dereferences a pointer. Its operand can be a pointer of any type except the generic Pointer, which must be typecast before dereferencing.
P = Q is True just in case P and Q point to the same address
otherwise, P <> Q is True.
可见 Pointer 指针类型明明是可以和 Integer 进行 +、-运算的呀!
var
P: Pointer;
I: Integer;
begin
P := P + I;
end;
编译时报错 "Operator not applicable to this operand type" !
P := P + 1 也不行![]
Inc(P)
倒可以,为什么??
查看 Delphi 中关于 Pointer 类型的说明如下:
The relational operators <, >, <=, and >= can take operands of type PChar (see Relational operators). The following operators also take pointers as operands. For more information about pointers, see Pointers and pointer types.
Operator Operation Operand types Result type Example
+ pointer addition character pointer, integer character pointer P + I
- pointer subtraction character pointer, integer character pointer, integer P - Q
^ pointer dereference pointer base type of pointer P^
= equality pointer Boolean P = Q
<> inequality pointer Boolean P <> Q
The ^ operator dereferences a pointer. Its operand can be a pointer of any type except the generic Pointer, which must be typecast before dereferencing.
P = Q is True just in case P and Q point to the same address
otherwise, P <> Q is True.
可见 Pointer 指针类型明明是可以和 Integer 进行 +、-运算的呀!