好久没更新了,今天整理了一下C++中模版的定义方法及其用法

      计算机与编程 2007-8-1 14:20:00

#include <iostream>
#include <string>

using namespace std;

template <class T,int I> class WANGS
{
 private :
  T array[I];
 public :
  void set (int x)
  {
   int i;
   for(i=0;i<I;i++)
    array[i]=x+i;
  }
  void get()
  {
   cout<<"\n the total number of array is: "<<I<<endl;
   cout<<"array["<<I-1<<"]="<<array[I-1]<<endl;
  }
 protected :
  int id_wangs; //nothing else...

};

void main()
{
 WANGS <int,50> wangs_1;
 wangs_1.set(0);
 wangs_1.get();

 WANGS <int,100> wangs_2;
 wangs_2.set(0);
 wangs_2.get();
}

标签集:TAGS:
回复Comments() 点击Count()
喜欢就顶一下

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}