c++ 模板联系4

//定义类成员函数特化类型
#include "stdafx.h"
#include <iostream>
using namespace std;

typedef float typeNew;

template<class T>
class MyClass
{
public:
	MyClass();
	~MyClass();
	T &Get(const T&);

private:
};

MyClass<typeNew>::MyClass()
{
}

MyClass<typeNew>::~MyClass()
{
}

typeNew & MyClass<typeNew>::Get(const typeNew&a)
{
	return const_cast<typeNew&>(a);
}

int _tmain(int argc, _TCHAR* argv[])
{
	MyClass<float> (mc);
	float &a = mc.Get(1230);
	cout<<a<<endl;

	return 0;
}

 

版权声明:本文为博主原创文章,未经博主允许不得转载。

 

posted @ 2015-06-14 11:48  QQ76211822  阅读(124)  评论(0编辑  收藏  举报