博客首页 注册 建议与交流 排行榜 加入友情链接
推荐 投诉 搜索: 帮助

自己学习的记录

不要说你不会,只是你还没有努力罢了!
  ZhangQuan.cublog.cn

关于作者
姓名:张佺
性别:男
职业:暂时失业,做自己的东西
年龄:24
位置:北京
个性介绍:天塌下来也会笑
Email:net_robber@tom.com
|| << >> ||
我的分类


C++模板用法:定义、使用 示例
我要啦免费统计

      1 #include <iostream>
      2 using namespace std;
      3 template < typename A, typename B>
      4 class test
      5 {
      6 public:
      7 test();
      8 ~test();
      9 int gX();
     10 };


     11 template < typename A, typename B>
     12 test< A, B >::test()
     13 {
     14 }


     15 template < typename A, typename B>
     16 test< A, B >::~test()
     17 {
     18 }


     19 template < typename A, typename B>
     20 int test< A, B >::gX()
     21 {
     22 cout<< sizeof(A)<<endl;
     23 cout<< sizeof(B)<<endl;
     24 return 0;
     25 }


     26 int main ( void )
     27 {
     28 test<int,char> x;
     29 x.gX();
     30 return 0;
     31 }



这定义方法真烦,为什么不能每个成员自动识别本类模板中的数据类型呢???

发表于: 2007-03-28,修改于: 2007-04-03 12:45,已浏览1124次,有评论0条 推荐 投诉


网友评论
 发表评论