某些类型虽然并没有提供类模板所需要的全部功能但照样可以实例化类模板,只要不调用那些未提供功能的成员函数即可
#include <iostream>
#include "test.h"
class Integer {
};
template<class 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;
};
int main() {
Integer t1, t2;
CMath<Integer> c(t1,t2);
//c.add();
return 0;
}
不调用add就能编译过