指针地址已更改 - 功能

时间:2014-07-10 15:55:46

标签: c++ function pointers

我有这段代码:

class pointLineVCN
{
public:
    int v, vc, vn;

    pointLineVCN(){};
    pointLineVCN(int v, int vc, int vn)
    {
        this->v = v;
        this ->vc = vc;
        this->vn = vn;
    }
};

pointLineVCN* newPoint;
void Triangulation3D(pointLineVCN* point, short numOfPoints)
{
    newPoint = new pointLineVCN[(numOfPoints - 2)  * 3];
    //Code which changes newPoint

    point = newPoint;
    cout<<point<<endl;
}

主要是:

pointLineVCN *vertices = new pointLineVCN[meshes[meshNum].face[*positionSaverFN].numOfPoints];

for (int i = 0; i < meshes[meshNum].face[*positionSaverFN].numOfPoints; i++)
{
    sscanf(bufferStr.c_str(), "%i/%i/%i", &faceVec, &faceTex, &faceNor);

    vertices[i].v = faceVec - 1;
    vertices[i].vc = faceTex - 1;
    vertices[i].vn = faceNor - 1;
}
Triangulation3D(vertices, meshes[meshNum].face[*positionSaverFN].numOfPoints);
cout<<vertices<<endl;

Triangulation3D结束后问题是point地址更改。在cout次调用中,输出是两个不同的地址。

我已经看到有关此问题的另一个问题,解决方案是使用pointLineVCN** point,但它没有帮助。

1 个答案:

答案 0 :(得分:1)

正在更改,因为您正在更改

point = newPoint;

如果您不想更改它,请不要这样做。