指向指针 SyntaxError 和不兼容类型的 Pascal 指针
Pascal pointer to pointer SyntaxError and Incompatible types
因为没有办法创建引用(是吗?)我必须用一个指向另一个指针的指针来做。这给了我一个错误:
type
PNode = ^TNode;
TNode = record
char: char;
next: PNode;
children: PNode;
end;
PPNode = ^PNode;
var
current_node: PPNode;
function find_or_insert_peer(var node: PNode; character: char): PNode;
current_node := @find_or_insert_peer(current_node^, character)^.children;
x.pas(121,23) Error: Incompatible types: got "<address of function(var PNode;Char):^TNode;Register>" expected "PPNode"
x.pas(121,43) Fatal: Syntax error, ";" expected but "(" found
Fatal: Compilation aborted
我也试过了,但是因为 SyntaxError 而无法编译
current_node := @(find_or_insert_peer(current_node^, character)^.children);
编辑
请帮忙。我什至用 C++ 创建了一个演示来向您展示这是合法的。 http://cpp.sh/8mxe
正如评论中链接的诙谐文章“Addressing pointers”中所述,@
运算符可能无法正确处理更复杂的表达式。它的等价物 addr()
就可以了。
current_node := addr(find_or_insert_peer(current_node^, character)^.children);
因为没有办法创建引用(是吗?)我必须用一个指向另一个指针的指针来做。这给了我一个错误:
type
PNode = ^TNode;
TNode = record
char: char;
next: PNode;
children: PNode;
end;
PPNode = ^PNode;
var
current_node: PPNode;
function find_or_insert_peer(var node: PNode; character: char): PNode;
current_node := @find_or_insert_peer(current_node^, character)^.children;
x.pas(121,23) Error: Incompatible types: got "<address of function(var PNode;Char):^TNode;Register>" expected "PPNode"
x.pas(121,43) Fatal: Syntax error, ";" expected but "(" found
Fatal: Compilation aborted
我也试过了,但是因为 SyntaxError 而无法编译
current_node := @(find_or_insert_peer(current_node^, character)^.children);
编辑
请帮忙。我什至用 C++ 创建了一个演示来向您展示这是合法的。 http://cpp.sh/8mxe
正如评论中链接的诙谐文章“Addressing pointers”中所述,@
运算符可能无法正确处理更复杂的表达式。它的等价物 addr()
就可以了。
current_node := addr(find_or_insert_peer(current_node^, character)^.children);