指向指针 SyntaxError 和不兼容类型的 Pascal 指针 [英] Pascal pointer to pointer SyntaxError and Incompatible types

查看:66
本文介绍了指向指针 SyntaxError 和不兼容类型的 Pascal 指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为没有办法创建引用(有吗?)我必须用一个指向另一个指针的指针来做.这给了我一个错误:

Since there's no way to create refereces (is there?) I have to do it with a pointer to another pointer. This gives me an error:

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 无法编译

I also tried this but it does not compile because of SyntaxError

current_node := @(find_or_insert_peer(current_node^, character)^.children);

编辑

请帮忙.我什至用 C++ 创建了一个演示来向你展示这是合法的.http://cpp.sh/8mxe

Please help. I've even created a demo in c++ to show you this is legal. http://cpp.sh/8mxe

推荐答案

正如在一篇诙谐的文章寻址指针" 在注释中链接 @ 运算符可能无法在更复杂的表达式中正常工作.其等效的 addr() 可以解决问题.

As mentioned in a witty-called article "Addressing pointers" linked in comments the @ operator might not work properly with more complex expressions. Its equivalent addr() will do the trick.

current_node := addr(find_or_insert_peer(current_node^, character)^.children);

这篇关于指向指针 SyntaxError 和不兼容类型的 Pascal 指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆