#include <iostream>
using namespace std;
#define PI 3.14
template<
class T>
T maxt(T x, T y)
{
return (x > y) ? x : y;
}
template<
typename T>
class Circle{
private:
T radius;
public:
Circle(){};
Circle(T r):radius(r){};
T area();
};
template<
typename T>
T Circle<T>::area()
{
return radius*radius*PI;
}
template<
typename T>
struct S_tmp{
T a;
};
template<
template<
typename S>
class T>
struct MyTest{
T<
int> test;
void show()
{
cout <<
"test show"<< endl;
}
};
int _tmain(
int argc, _TCHAR* argv[])
{
MyTest<S_tmp> TT;
TT.show();
return 0;
}
template<
typename RT,
typename T,
typename S>
RT mymax(T a, S b)
{
return (a > b) ? a : b;
}
template<
typename T,
typename S>
auto mymax2(T a, S b)->
decltype(a*b)
{
return (a > b) ? a : b;
}
int _tmain(
int argc, _TCHAR* argv[])
{
cout << mymax<
double,
int,
double>(
5,
6.2) << endl;
cout << mymax<
double>(
5,
6.2) << endl;
cout << mymax2(
5,
6.2) << endl;
return 0;
}
指针实参
和前面一样
T show(T a)
{
return a;
}
int _tmain(
int argc, _TCHAR* argv[])
{
double a =
5;
double* pd = &a;
cout <<*show(pd) << endl;
return 0;
}