编译报错: test.cpp: In function `int main()': test.cpp:8: no method `safe_map<int, int, std::less<int>, std::allocator<std::pair<const int, int> > >::value_type' test.cpp:10: `iterator' is not a member of type `safe_map<int, int, std::less<int>, std::allocator<std::pair<const int, int> > >' test.cpp:10: syntax error before `=' token test.cpp:10: `it' undeclared (first use this function) test.cpp:10: (Each undeclared identifier is reported only once for each function it appears in.) test.cpp:10: no matching function for call to `safe_map<int, int, std::less<int>, std::allocator<std::pair<const int, int> > >::end()' test.cpp:12: `cout' undeclared (first use this function) test.cpp:12: `endl' undeclared (first use this function) g++: compilation of header file requested
------解决方案-------------------- 首先, 最好不要从标准模板库的容器类派生 另外, map的模板参数也不能丢掉了 template <class _Key, class _Tp, class _Compare = less <_Key>, class _Alloc = allocator <pair <const _Key, _Tp> > > class safe_map:public std::map<...> { 这里还需要加上一堆的typedef, 比如value_type之类的 };
------解决方案--------------------