0

我有一个带有 3 个浮点 xyz(3-D 空间中的坐标)的 point3 结构。

我创建了几个 point3 的实例,然后创建一个列表并将这些实例推送到列表中。然后我将翻译功能应用于整个列表。

问题:应用翻译后,如何打印列表中某个点的 X 坐标以检查我的翻译功能是否符合我的要求?

这是我的代码:

int main()
{   
    point3 p1 = point3(0.0f, 0.0f, 0.0f);
    point3 p2 = point3(1.0f, 1.0f, 1.0f);
    point3 p3 = point3(2.0f, 2.0f, 2.0f);

    list<point3> myList;
    myList.push_front(p1);
    myList.push_front(p2);
    myList.push_front(p3);

    list<point3> myList2 = translateFact(myList, 1, 1, 1);

    std::cout << myList2.front.x; //<--- This is the line I'm having trouble with
}

//Translates the face by dx, dy, dz coordinates
list<point3> translateFact(list<point3> lop, float dx, float dy, float dz)
{
    list<point3>::iterator iter;

    for (iter = lop.begin() ; iter != lop.end(); iter++){
        point3 p = *iter;
        iter->x - dx;
        iter->y - dy;
        iter->z - dz;
    }
    return lop;
}

尝试打印 myList2.front.x 时收到的错误是

IntelliSense: a pointer to a bound function may only be used to call the function

所以我认为我的问题与指针有关,但我不确定如何。我最近刚开始学习 C++,所以我对诊断/修复错误的指针知之甚少。

4

1 回答 1

2

您需要括号来表示您要调用该front方法:

std::cout << myList2.front().x;
于 2012-04-18T01:21:22.417 回答