Collecting Parameter ¶
몇몇 메드 결과 력는 렉 떻게 리것가?(?)
ComposedMethod 단 나는, 메드들 관때문다. 메드 나 공되던 변들, 는 메드들 공된다. 가 결기 방법 ComposedMethod를 고 다 나 메드 다 때려는 것만, 다. 또 다른 결로는 메드들 공되는 변를 멤변 는 것다. 것 객 명기 동 게 라, 메드들 될때만 다. 다.
리 결, 메드들다 라메들 겨는 것다. 것 망는 방법긴 나, 다른 것들보단 낫다.
떤 렉 기남과 미녀를 내는 드를 보.
~cpp vector<People> marriedMenAndUnmarriedWomen() { vector<People> result; for(vector<People>::iterator it = result.begin() ; it != result.end() ; ++it) { if(it->isMarried() and it->isMan()) result.add(*it); } for(vector<People>::iterator it = result.begin() ; it != result.end() ; ++it) { if(it->isUnmarried() and it->isWoman()) result.add(*it); } return result; }ComposedMethod를 보.
~cpp vector<People> marriedMen() { vector<People> result; for(vector<People>::iterator it = result.begin() ; it != result.end() ; ++it) { if(it->isMarried() and it->isMan()) result.add(*it); } return result; } vector<People> unmarriedMen() { vector<People> result; for(vector<People>::iterator it = result.begin() ; it != result.end() ; ++it) { if(it->isUnmarried() and it->isWoman()) result.add(*it); } return result; } vector<People> marriedMenAndUnmarriedWomen() { return marriedMen() + unmarriedMen(); // 될 될는 모르겠만 된다고 가. }
렉 리 말고 각각 렉 더.
~cpp vector<People> marriedMenAndUnmarriedWomen() { vector<People> result; addMarriedMenTo(result); addUnmarriedWomenTo(result); return result; } void addMarriedMen(vector<People>& aCollection) { for(vector<People>::iterator it = result.begin() ; it != result.end() ; ++it) { if(it->isMarried() and it->isMan()) aCollection.add(*it); } } void addUnmarriedMen(vector<People>& aCollection) { for(vector<People>::iterator it = result.begin() ; it != result.end() ; ++it) { if(it->isUnmarried() and it->isWoman()) aCollection.add(*it); } }
, 두 메드 결과를 모는 경데, 그리 경는 던로 기. 다르긴 만 나 경 CollectionParameter 격로 경가 read/write I/O 가 내부로 때 또는 Serialization 때. 그 경 I/O 부 Stream 래로 만들고(C++ Stream 던 또는 Stream 래 만들 던) parameter 로 겨고 그 라메 메드를 는 . --1002