5
C ++ 맵 액세스가 한정자를 버림 (const)
다음 코드는 맵을 메소드 const로 전달하면 operator[]한정자가 삭제됩니다. #include <iostream> #include <map> #include <string> using namespace std; class MapWrapper { public: const int &get_value(const int &key) const { return _map[key]; } private: map<int, int> _map; }; int main() { MapWrapper mw; cout << mw.get_value(42) << endl; return 0; } 맵 …