#include <iostream>
using namespace std;
template <typename T>
void ShowMax(T a, T b)
{
cout << "a=" << a;
cout << ",b=" << b;
cout << ",a + b=" << a + b;
cout << endl;
}
template <typename T>
void show(T * a)
{
cout << "show a=" << *a << endl;
}
int main()
{
int *pint;
int p = 4;
pint = &p;
show(pint);
ShowMax(3,5);
ShowMax('3','5');
system("PAUSE");
return 0;
}
本文通过两个模板函数ShowMax和show展示了C++中模板函数的应用。ShowMax函数用于展示两个相同类型参数的值及其和,而show函数则用于展示指针所指向的整数值。通过具体的示例调用,如传递整数3和5给ShowMax函数,以及通过指针展示变量p的值,直观地解释了模板函数的功能。
826

被折叠的 条评论
为什么被折叠?



