English 中文(简体)
通过C++中的要点清单进行
原标题:Iterating through a list of points in C++

我有一个点3,即3个浮体×, y, z(3-D空间坐标)。

I m trying to write a function that translates the x, y, z values of each element in a list of points.

I m new to C++ so, 我想我不认为我写的是正确的,谁能帮助澄清如何编造清单和修改清单中每个要素的内容?

我看见这一员额:C++ 如何通过一份结构清单和获取其财产,并认为这回答了我的问题,但解决办法却未奏效。

我的守则是:

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

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

我也尝试了上述联系中提出的解决办法,但还是没有工作。 是否在休息室内外? 我是否应该回到除虫以外的东西?

for (iter = lop.begin() ; iter != lop.end(); iter++){
    (*iter).x - dx;
    (*iter).y - dy;
    (*iter).z - dz;
    }
return lop;
最佳回答

在我看来,你实际上不是storing。 您的计算结果:

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

引证:

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

我希望,大多数汇编者会发出警告,不要像现在这样进行未使用的计算——如果你能够的话,就会把警告水平提升到你的编辑上。

问题回答

参看:

list<point3> translateFace(list<point3> lop, float dx, float dy, float dz)
{
    list<point3>::iterator iter;

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

    return lop;
}

如果是正确的选择,假定你知道,如果你这样做,你会重新制作一个地方比例参数的复印件,然后将其送回并移走(C++0x)或复制(C++03),然后将其输入你所设定的任何变量。 例如(假设点3包括3个浮点以建造):

point3 point(0.0, 0.3, 0.5);
list<point3> face;

face = translateFace(list<point3>(point), -0.5, -3.32, -7.5);

清单应仅载有点,坐标为5、3.02和-7.0。





相关问题
Finding a class within list

I have a class (Node) which has a property of SubNodes which is a List of the Node class I have a list of Nodes (of which each Node may or may not have a list of SubNodes within itself) I need to be ...

How to flatten a List of different types in Scala?

I have 4 elements:List[List[Object]] (Objects are different in each element) that I want to zip so that I can have a List[List[obj1],List[obj2],List[obj3],List[obj4]] I tried to zip them and I ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

Is List<> better than DataSet for UI Layer in ASP.Net?

I want to get data from my data access layer into my business layer, then prepare it for use in my UI. So i wonder: is it better to read my data by DataReader and use it to fill a List<BLClasses&...

What is the benefit to using List<T> over IEnumerable<T>?

or the other way around? I use generic lists all the time. But I hear occasionally about IEnumerables, too, and I honestly have no clue (today) what they are for and why I should use them. So, at ...

灵活性:在滚动之前显示错误的清单

我有一份清单,在你滚动之前没有显示任何物品,然后这些物品就显示。 是否有任何人知道如何解决这一问题? 我尝试了叫人名单。

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签