小步慢跑

 

成员模版方法vc和g++的语法差异

foo.h

   1: #ifndef _FOO_H_
   2: #define _FOO_H_
   3: #include <stdio.h>
   4: #include<iostream>
   5: #include<string>
   6:  
   7: class foo
   8: {
   9: public:
  10:     template<typename T>
  11:         void Saytype(const T&)
  12:     {
  13:         std::cout <<"unrecognized  type !"<<std::endl;
  14:     }
  15:  
  16:     // 下面的全特化在 vc6下编译通过,但g++ 4.1.2 编译失败
  17: //     template<>
  18: //         void Saytype<int>(const int & )
  19: //     {
  20: //         std::cout<<" type is int";
  21: //     }
  22:     // g++上可以使用重载来代替全特化
  23:     void Saytype(const int &)
  24:     {
  25:         std::cout<<" type is int";
  26:     }
  27: };
  28:  
  29: #endif

main.cpp

   1: #include "../include/foo.h"
   2:  
   3: int main()
   4: {
   5:     
   6:     foo f;
   7:     f.Saytype((unsigned int)1);
   8:     f.Saytype((int)1);
   9:  
  10:     return 1;
  11: }

posted on 2013-01-10 15:15 zaccheo 阅读(302) 评论(0)  编辑 收藏 引用 所属分类: C++


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


导航

统计

常用链接

留言簿

随笔分类(23)

随笔档案(26)

文章分类(1)

文章档案(1)

csdn

搜索

最新评论

阅读排行榜

评论排行榜