标签:相同 name 思想 文件中 san clu namespace operator tac
template <typename T>
{
public:
T op(T a,T b);
};
Operator<int> op1;
Operator<string> op2;
int i = op1.op(1,2);
string s = op2.op("CHENGE","HANDSOME");
#include <iostream>
#include <string>
using namespace std;
template <typename T>
class Operator
{
public:
T add(T a,T b)
{
return a + b;
}
T minus(T a,T b)
{
return a - b;
}
T multiply(T a, T b)
{
return a * b;
}
T divide(T a,T b)
{
return a / b;
}
};
int main()
{
Operator<int> op1;
cout << op1.add(1, 2) << endl;
}
#include <iostream>
#include <string>
#include "operator.h"
using namespace std;
int main()
{
Operator<int> op1;
cout << op1.add(1, 2) << endl;
}
#ifndef _OPEARTOR_H_
#define _OPERATOR_H_
template <typename T>
class Operator
{
public:
T add(T a, T b);
T minus(T a, T b);
T multiply(T a, T b);
T divide(T a, T b);
};
template <typename T>
T Operator<T>::add(T a, T b)
{
return a + b;
}
template <typename T>
T Operator<T>::minus(T a, T b)
{
return a - b;
}
template <typename T>
T Operator<T>::multiply(T a, T b)
{
return a * b;
}
template <typename T>
T Operator<T>::divide(T a, T b)
{
return a / b;
}
#endif
标签:相同 name 思想 文件中 san clu namespace operator tac
原文地址:https://www.cnblogs.com/chengeputongren/p/12273351.html