免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3752 | 回复: 5
打印 上一主题 下一主题

写了个template,编译总是报错 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-04-27 09:27 |只看该作者 |倒序浏览
我对template没有怎么写过,现在写了个template,但是怎么编译都不通过, 可能是不能这么用,所以想问问大家,我用的是gcc编译器,在hp-ux上的代码:

template<class T>
class ThreadLocal
{
  //typedef std::map<pthread_t,T*> ThreadLocalMap;
  public:
    void put(T* elem)
    {
      //mutex protect.
      //MutexGuard guard(mapMutex);
      pthread_t tid = pthread_self();
      
      //theadLocalMap.insert(std::map<pthread_t,T*>::value_type(tid,elem));
    }
   
    T* get()
    {
      //mutex protect.
      //MutexGuard guard(mapMutex);
      pthread_t tid = pthread_self();
      
      //std::map<int,T> maptt;
      std::list<T>::iterator iter;
      return NULL;
    }
   
    void remove()
    {
      //mutex protect.
      //MutexGuard guard(mapMutex);
      pthread_t tid = pthread_self();
      theadLocalMap.erase(tid);
    }
   
  private:
    std::map<pthread_t,T*> theadLocalMap;
    //MICOMT::Mutex mapMutex;
   
};

错误信息为:
In file included from dbtoolkit.h:5,
                 from dbtoolkit.cc:1:
threadlocal.h: In member function `T* ThreadLocal<T>::get()':
threadlocal.h:107: error: expected `;' before "iter"
threadlocal.h: In member function `T* ThreadLocal<T>::get() [with T = OraSession]':
dbtoolkit.cc:75:   instantiated from here
threadlocal.h:107: error: dependent-name ` std::list<T,std::allocator<_CharT> >::iterator' is parsed as a non-type, but instantiation yields a type

threadlocal.h:107: note: say `typename  std::list<T,std::allocator<_CharT> >::iterator' if a type is meant

如果我把std::list<T>::iterator iter; 修改为std::list<int>::iterator iter;编译通过, 如果直接std::list<T> list; 编译也是通过的,调用其他方法也行,就是只要使用了iterator,就编译报错,不光是list,map也是这样

论坛徽章:
0
2 [报告]
发表于 2007-04-27 10:06 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
3 [报告]
发表于 2007-04-27 11:48 |只看该作者
我试了,还是不行啊,报告相同的错误,同样的代码在vc下一点问题没有.
急死了,代码都写好了,就这个地方弄不过,麻烦各位指点迷津.

论坛徽章:
0
4 [报告]
发表于 2007-04-27 11:50 |只看该作者
可以了,就是用这个typename, 先前我搞错了,这下对了,多谢xiaomiao (一笛风)  拉.太感谢了.

论坛徽章:
0
5 [报告]
发表于 2007-04-27 15:01 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
6 [报告]
发表于 2007-04-27 15:05 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP