C++ 模板类

来源:互联网 发布:网络诈骗立案金额标准 编辑:程序博客网 时间:2024/06/05 20:34

//头文件

#ifndef PERSON_H

#define PERSON_H


template <typename T>
class Person
{
public:
    Person();
    virtual ~Person();
    T fun1(T a);
    void fun2(T a);
protected:
private:
};

#endif // PERSON_H

//实现类



#include "Person.h"
#include <iostream>


using namespace std;


template <typename T>
Person<T>::Person()
{
    //ctor
}


template <typename T>
T Person<T>::fun1(T a){


   return a;


}


template <typename T>
void Person<T>::fun2(T a){


 cout<<"fun2";


}


template <typename T>
Person<T>::~Person()
{
    //dtor
}



0 0
原创粉丝点击