using namespace std;
#define _DEBUG_FUNCTION_TEMPLATE
#define _DEBUG_CLASS_TEMPLATE
#ifdef _DEBUG_FUNCTION_TEMPLATE
/*函数模版*/
template<class T>
T Add(T a, T b){
T c;
c = a+b;
cout<<"函数模版内计算结果:"<<c<<endl;
return c;
}
#endif
#ifdef _DEBUG_CLASS_TEMPLATE
template<class T>
class TempClass{
public:
TempClass(){};//注意要有{}
T Add(T a, T b){
T c;
c = a+b;
cout<<"类模版内计算结果:"<<c<<endl;
return c;
};
virtual ~TempClass(){};
}; //注意要有;
#endif
int main()
{
#ifdef _DEBUG_FUNCTION_TEMPLATE
cout<<"调用函数模版计算结果:"<<Add<int>(3,4)<<endl;
#endif
#ifdef _DEBUG_CLASS_TEMPLATE
TempClass<int> templt;
cout<<"调用类模版计算结果:"<<templt.Add(3,4)<<endl;
#endif
return 0;
}