博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

测试在class template中有static data members

Posted on 2011-08-22 15:43  ChessYoung  阅读(156)  评论(0编辑  收藏  举报
#include "stdafx.h"
#include
<iostream>
#include
<assert.h>
#include
<string>
#include
<vector>
using namespace std;

template
<typename T>
class testclass
{
public:
static int _data;
};

int testclass<int>::_data = 1;
int testclass<char>::_data = 2;

int _tmain(int argc, _TCHAR* argv[])
{
cout
<< testclass<int>::_data << endl;
cout
<< testclass<char>::_data << endl;

testclass
<int> obji1,obji2;
testclass
<char> objc1,objc2;

cout
<< obji1._data << endl;
cout
<< obji2._data << endl;
cout
<< objc1._data << endl;
cout
<< objc2._data << endl;

obji1._data
= 3;
objc2._data
= 4;

cout
<< obji1._data << endl;
cout
<< obji2._data << endl;
cout
<< objc1._data << endl;
cout
<< objc2._data << endl;

return 0;
}