全类特化:特化一个类模板可以特化该类模板所有的成员函数,相当于重新写了一个针对某种特定类型的具体类
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
template<typename T>
class CMath {
public:
CMath(const T& t1, const T& t2):m_t1(t1),m_t2(t2) {}
T add() { return m_t1 + m_t2; }
private:
T m_t1;
T m_t2;
};
template<>
class CMath<const char*> {
public:
CMath(const char* t1, const char* t2) :m_t1(t1), m_t2(t2) {}
char* add() { return strcat(const_cast<char*>(m_t1),m_t2); }
private:
const char* m_t1;
const char* m_t2;
};
int main() {
return 0;
}