1
我有以下代碼:如何創建容器持有策略類型的容器迭代器?
#include <map>
#include <string>
class policy1
{
public:
struct data
{
};
};
template<typename policy>
class policy_user : public policy
{
typedef std::map<std::string, typename policy::data> mymap; // good
typedef std::map<std::string,
typename policy::data >::iterator myiterator; // bad
typedef mymap::iterator myseconditerator; // also bad
};
失敗有:
der.cpp:17: error: type ‘std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, typename policy::data, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, typename policy::data> > >’ is not derived from type ‘policy_user<policy>’
der.cpp:17: error: expected ‘;’ before ‘myiterator’
der.cpp:18: error: type ‘std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, typename policy::data, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, typename policy::data> > >’ is not derived from type ‘policy_user<policy>’
der.cpp:18: error: expected ‘;’ before ‘myseconditerator’
而且我不知道爲什麼。任何幫助我如何完成我嘗試做的事情(創建一個迭代器)?