다음 상황에서 sortMyVectors
의 매개 변수 목록은 어떻게 나타나야하며 myFunction
에서 어떻게 호출합니까?벡터를 함수 (포인터/주소)로 전달
std::vector<Vector2> myFunction (MyObj * myObj) {
std::vector<Vector2> myVectors;
// fill with lots of Vector2(double x, double y) objects
sortMyVectors(???-myVectors, ???-myObj);
return myVectors;
}
void sortMyVectors(vector<Vector2> &myVectors, const MyObj &myObj) {
// sort the std::vector using myObj
// modifies order of Vector2s within the passed-in myVectors
// does not modify myObj
// need to be able to access with myVectors[0].x here...
}
이 호출되는 방법은 myObj
가 list<MyObj>::iterator
이고, myFunction(&(*myObj));
입니다. 이것을 작성하는 더 깨끗한 방법이 있습니까?
'sortMyVectors (myVectors, * myObj); "myVectors"는 변수이므로 직접 참조로 전달할 수 있습니다. 'myObj'는 포인터이므로,'MyObj '와 호환되도록 포인터를 한 번 역 참조 할 필요가 있습니다. – dasblinkenlight
어떤 오류가 발생합니까? 설명을 위해 – dasblinkenlight
Thx."sortMyVectors (std :: vector <_Vector2, std :: allocator <_Vector2>>, & MyObj &)'" " – Ben