模板问题,在windows下正常,在linux下编译报错

lurenyy 2011-12-01 11:51:56


template<typename Key,typename Type,typename Allocator>
struct StoreObject
{
StoreObject(const Key & key,const Type &data);

typedef StoreObject<Key,Type,typename Allocator::rebind< Type >::other> ObjectType;
typedef std::list<ObjectType *,typename Allocator::rebind< ObjectType * >::other> ListType;

};


这段代码在windows下使用正常,现在想移植到linux下,编译出错,请大家帮忙看看啦。。
贴出typedef StoreObject<Key,Type,typename Allocator::rebind< Type >::other> ObjectType;这行的错误

error: non-template `rebind' used as template
note: use `Allocator::template rebind' to indicate that it is a template
error: missing `>' to terminate the template argument list
error: template argument 3 is invalid

...全文
146 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
iamnobody 2011-12-01
  • 打赏
  • 举报
回复
typedef std::list<ObjectType *,typename Allocator::template rebind< ObjectType * >::other> ListType;

加多一个template试试
lurenyy 2011-12-01
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 pengzhixi 的回复:]
Allocator< ObjectType *>::rebind< ObjectType * >::other试试吧
[/Quote]
不能这样。。。
pengzhixi 2011-12-01
  • 打赏
  • 举报
回复
Allocator< ObjectType *>::rebind< ObjectType * >::other试试吧
lurenyy 2011-12-01
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 stormlk1983 的回复:]
吧C++primer再仔细看看吧,里面好像是有模板特化这一节的
同一个模板结构里程序不能既显示实例化,同时又显式特化
[/Quote]

这个可以有。。。
夹心饼干 2011-12-01
  • 打赏
  • 举报
回复
吧C++primer再仔细看看吧,里面好像是有模板特化这一节的
同一个模板结构里程序不能既显示实例化,同时又显式特化
  • 打赏
  • 举报
回复
typedef StoreObject<Key,Type,typename Allocator::template rebind< Type >::other> ObjectType;
typedef std::list<ObjectType *,typename Allocator::template rebind< ObjectType * >::other> ListType;
夹心饼干 2011-12-01
  • 打赏
  • 举报
回复
typename Allocator::rebind< Type >::other 普通的模板
typename Allocator::rebind< ObjectType * >::other 模板特化
这样一起用?

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧