将指针变量设置为多个值

丹三

我正在使用自定义链接列表类的代码。列表类具有以下功能:

void linkedList::expire(Interval *interval, int64 currentDt)
{
    node *t = head, *d;
    while ( t != NULL )
    {
        if ( t->addedDt < currentDt - ( interval->time + (((long long int)interval->month)*30*24*3600*1000000) ) )
        {
            // this node is older than the expiration and must be deleted
            d = t;
            t = t->next;

            if ( head == d )
                 head = t;

            if ( current == d )
                 current = t;

            if ( tail == d )
                 tail = NULL;

             nodes--;
             //printf("Expired %d: %s\n", d->key, d->value);
             delete d;
         }
         else
         {
            t = t->next;
         }
     }
}

我不明白的是函数中的第一行代码:

node *t = head, *d;

该代码如何编译?您如何为一个变量分配两个值,或者这是一些捷径?head是* node类型的成员变量,但在其他任何地方都找不到d。

卡达尼鲁克

这是两个定义,不是逗号操作符1它们相当于

node* t = head;
node* d;

1逗号运算符在C ++中的优先级最低,因此调用它需要使用括号:

node* t = (head, *d);

如果d类型为,这将正常工作node**

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章