C++模板中的静态

来源:互联网 发布:js或 编辑:程序博客网 时间:2024/05/29 19:07
#include <iostream>#include <stdlib.h>using namespace std;template<class T>class xiaok{public:  static void han(){cout<<"xiao"<<endl;}  static void han1();  static int i; // static const int ii=0; //vc.6报错};int xiaok<int>::i=1;int xiaok<char>::i=2;template<class T> int xiaok<T>::i=0;void xiaok<int>::han1(){cout<<"int"<<endl;}void xiaok<char>::han1(){cout<<"char"<<endl;}template<class T> void xiaok<T>::han1(){cout<<"T"<<endl;}int main(int argc, char const *argv[]){xiaok<int> wi;xiaok<char> wc;xiaok<long> wl;cout<<xiaok<int>.i<<endl;cout<<wc.i<<endl;cout<<xiaok<long>.i<<endl;wi.han1();xiaok<char>::han1();wl.han1();wl.han();return 0;}

0 0
原创粉丝点击