Node是什么类型的?

时间:2011-05-05 02:31:36

标签: c++ c

我必须使用这个参数完成void initRT(Node * n;)。我该怎么办?

struct RtPkt{
    int sourceid;
    int destid;
    int mincost[5];
};

struct  dr_table {
    int costs[5];
    int nexthop[5];
};


int connectcosts[NUMNODES][NUMNODES];

/* Setup the network costs */
void initcosts() {
static int initialized = 0;
if (!initialized) {
    /* initialize by hand since not all compilers allow array initilization */
    connectcosts[0][1] = connectcosts[1][0] = 1; // x0
    connectcosts[1][2] = connectcosts[2][1] = 1; // x1
    connectcosts[2][3] = connectcosts[3][2] = 2; // x2
    connectcosts[0][3] = connectcosts[3][0] = 6; // x3
    connectcosts[1][4] = connectcosts[4][1] = 5; // x4
    connectcosts[0][2] = connectcosts[2][0] = 4; // x5
    connectcosts[3][4] = connectcosts[4][3] = 1; // x6

    /* Not connected nodes */
    connectcosts[0][4] = connectcosts[4][0] = connectcosts[1][3] =
        connectcosts[3][1] = connectcosts[2][4] = connectcosts[4][2] =
        999;

    /* Loopback links */
    connectcosts[0][0] = connectcosts[1][1] = connectcosts[2][2] =
        connectcosts[3][3] = connectcosts[4][4] = 0;
    }
}

/**
 * H synarthsh ayth pairnei san orisma enan deikth se Node. To pedio
 * id ths domhs prepei na einai arxikopoihmeno sto index toy komboy (p.x.
 * 0 gia to node 0, 1 gia to node 1, kok) H synarthsh ayth prepei na
 * arxikopoihsei to routing table toy komboy me bash ton pinaka connectcosts
 * poy orizetai kai arxikopoieitai sto node.c kai katopin na steilei ena
 * katallhlo RtPkt se oloys toys geitonikoys komboys toy node.
 */

 struct RtPkt packet;
void initRT(Node *n;) {
    int i,j;
packet.sourceid=i;
for (i=0;i<5;i++)
    for (j=0;j<5;j++)
        {
        n->costs[i]=connectcosts[i][j];
    }
    packet.mincost[i]=n.costs[i];
    if (packet.sourceid=0)
        {

            n->nexthop[0]=0;
            n->nexthop[1]=1;
            n->nexthop[2]=2;
            n->nexthop[3]=3;
            n->nexthop[4]=999;

            tolayer2(packet);
            packet.destid=1;
            tolayer2(packet);

            packet.destid=2;
            tolayer2(packet);

            packet.sourceid=3;
            tolayer2(packet);
        }
    else if (packet.sourceid=1)
        {
            n->nexthop[0]=0;
            n->nexthop[1]=1;
            n->nexthop[2]=2;
            n->nexthop[3]=999;
            n->nexthop[4]=4;

            tolayer2(packet);
            packet.destid=0;
            tolayer2(packet);

            packet.destid=2;
            tolayer2(packet);

            packet.sourceid=4;
            tolayer2(packet);
        }
    else if (packet.sourceid=2)
        {
                n->nexthop[0]=0;
                n->nexthop[1]=1;
                n->nexthop[2]=2;
                n->nexthop[3]=3;
                n->nexthop[4]=999;

                tolayer2(packet);
                packet.destid=0;
                tolayer2(packet);

                packet.destid=1;
                tolayer2(packet);

                packet.sourceid=3;
                tolayer2(packet);
        }
    else if (packet.sourceid=3)
        {
                n->nexthop[0]=0;
                n->nexthop[1]=999;
                n->nexthop[2]=2;
                n->nexthop[3]=3;
                n->nexthop[4]=4;

                tolayer2(packet);
                packet.destid=0;
                tolayer2(packet);

                packet.destid=2;
                tolayer2(packet);

                packet.sourceid=4;
                tolayer2(packet);
        }
    else if (packet.sourceid=4)
        {
                n->nexthop[0]=0;
                n->nexthop[1]=999;
                n->nexthop[2]=2;
                n->nexthop[3]=3;
                n->nexthop[4]=4;

                tolayer2(packet);
                packet.destid=1;
                tolayer2(packet);

                packet.destid=3;
                tolayer2(packet);

        }


    }

}

2 个答案:

答案 0 :(得分:2)

您创建的结构或类必须是Node的子类,那么您应该没有问题将该类型的对象传递给initptr函数。

答案 1 :(得分:1)

void yourcode()
{

    // declare an instance of a node on the stack
    Node n;

    // pass it by pointer to the initptr function
    initptr(&n);

}