我有一个point3结构,有3个浮点x y z(三维空间中的坐标)。
我创建了一些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 ++所以我对指针诊断/修复错误知之甚少。
答案 0 :(得分:2)
您需要括号表示您要调用front
方法:
std::cout << myList2.front().x;