如何使用保存策略类型的容器创建容器迭代器?
我有以下代码:
#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’
我不知道为什么。有什么帮助我可以完成我尝试做的事情(创建迭代器)吗?
I have the following code:
#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
};
that fails with:
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’
And I have no clue why. Any help how I can accomplish what I try to do (create an iterator)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您忘记了 typedef 中的
typename
。写:
现在。没关系。
typename
是必需的,因为iterator
是 从属名称。另请参阅 这个You forgot
typename
in typedefs.Write:
Now. It's fine.
typename
is required becauseiterator
is a dependent name. See also this