码迷,mamicode.com
首页 > 编程语言 > 详细

C++模板中的静态

时间:2015-06-07 11:11:36      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:c++

#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;
}

C++模板中的静态

标签:c++

原文地址:http://blog.csdn.net/h1023417614/article/details/46398303

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!