C++ 将指针变量设置为多个值

C++ 将指针变量设置为多个值,c++,pointers,variable-assignment,C++,Pointers,Variable Assignment,我正在编写使用自定义链表类的代码。list类具有以下功能: 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)*

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

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**

这是两个定义,而不是1,则这将正常工作。它们相当于

node* t = head;
node* d;

1,逗号运算符在C++中所有操作符的优先级最低,因此调用它需要偏执:

node* t = (head, *d);

<> p> > <>代码> d>代码>类型>节点**>代码> .< /p> 。通常C++中可以列出多个定义,用逗号分隔:

int a,b,c,d;
将定义4个整数。危险在于指针的处理方式可能不明显:

int* a,b,c,d;
将声明a为指向int的指针,其余的将仅为int。因此,在样式中声明指针的做法并不少见:

int *a, *b; 

声明两个整数指针。

,通常在C++中,可以列出多个定义,用逗号分隔它们:

int a,b,c,d;
将定义4个整数。危险在于指针的处理方式可能不明显:

int* a,b,c,d;
将声明a为指向int的指针,其余的将仅为int。因此,在样式中声明指针的做法并不少见:

int *a, *b; 
它声明了两个整数指针