[問題] Template函式範本的問題....
向各位大大請益,這是我在書中所看到的範例...
但我覺得有問題的部份就是
為什麼template的命名是maxt而在main function去呼叫時是用max?
這是我個人很困擾,也不曉得其中機轉的部份!
可以請各位幫我解答嗎?謝謝....
我的作業環境是Visual Studio 2008
以下是程式碼:
#include <iostream>
using namespace std;
template <class T>
T maxt( T x, T y)
{
if(x>y)
return x;
else
return y;
}
int main()
{
int a,b;
double da,db;
cout << "Please input 2 int: " << endl;
cin >> a >> b;
cout << "Please input 2 double : " << endl;
cin >> da >> db;
int ans1 = max(a, b);
double ans2 = max(da, db);
cout << " Max int = " << ans1 << endl;
cout << " Max double = " << ans2 << endl;
return o;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.67.147.111
推
02/10 13:05, , 1F
02/10 13:05, 1F
→
02/10 13:06, , 2F
02/10 13:06, 2F
→
02/10 13:09, , 3F
02/10 13:09, 3F
→
02/10 13:11, , 4F
02/10 13:11, 4F
→
02/10 13:24, , 5F
02/10 13:24, 5F
→
02/10 13:28, , 6F
02/10 13:28, 6F
→
02/10 13:30, , 7F
02/10 13:30, 7F
推
02/10 13:35, , 8F
02/10 13:35, 8F
推
02/10 13:52, , 9F
02/10 13:52, 9F
→
02/10 13:52, , 10F
02/10 13:52, 10F
→
02/10 14:12, , 11F
02/10 14:12, 11F
→
02/10 14:13, , 12F
02/10 14:13, 12F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章