아무도 반복기 문제로 나를 도와 줄 수 있습니까? 내가, 내가 구조체의 외부 (정의)지도 반복자를 만드는 문제에 봉착 언급 한 방법으로C++ typedef, map, iterator
class SomeClass{
public:
//Constructor assigns to m_RefPtr a new t_Records
//Destructor deletes m_RefPtr or decreases m_RefCnt
//Copy Constructor assigns m_RefPtr to new obj, increases m_RefCnt
bool Search(const string &);
private:
//Some private variables
struct t_Records{ //For reference counting
int m_RefCnt; //Reference counter
typedef vector<int> m_Vec;
typedef map<string, m_Vec> m_Map;
m_Map m_RecMap;
t_Records(void){
m_RefCnt = 1;
}
};
t_Records * m_RefPtr;
};
//Searchs through the map of m_RefPtr, returns true if found
bool SomeClass::Search(const string & keyword){
//How to create and use an iterator of m_Map???
return true;
}
:이 같은 뭔가가 있어요. 지도는 초기화되어 있으며 일부 레코드가 포함되어 있습니다. 답장을 보내 주셔서 감사합니다. 이처럼
을 더욱 쉽게처럼 반복 할 수 있습니다! –
'auto'를 사용할 수 있습니까? – Deduplicator
해당 디자인에서 잠재적 인 문제점을 제기 할 여러 출처가 있습니다. 이 시점에서 당신에 관해 무엇이 관련이 있습니까? 유형? 반복기를 반환하는 방법? 'm_RefPtr'의 평생 확장? * 내부 모든 요소에 대한 반복자 (예 : * 모든 * std :: vector?) --BTW, 이것은 shared_ptr을 다시 구현하는 것처럼 보입니다. 표준 스마트 포인터를 사용하는 것이 좋습니다. 이. –