[問題] template with visual studio
開發平台(Platform): (Ex: VC++, Gcc, Linux, ...)
VC++
額外使用到的庫(Library Used) (Ex: OpenGL, ...)
問題(Question):
照著程式教學書上打的程式,不知道為何會出錯
想說應該是編譯器的種類原因
不知道要改成怎樣才可以QQ
程式碼(Code): (請善用置底文標色功能)
#include"stdafx.h"
#include<iostream>
using namespace std;
template <typename Q>
Q happy (Q x, Q y,Q z)
{
Q max=max(x,y,z);
return max;
}
int main()
{
int a,b,c;
double d,e,f;
char g,h,i;
cout<<"Integer:";
cin>>a>>b>>c;
cout<<"Double:";
cin>>d>>e>>f;
cout<<"Char:";
cin>>g>>h>>i;
cout<<"The max is "<<happy(a,b,c);
cout<<"The max is "<<happy(d,e,f);
cout<<"The max is "<<happy(g,h,i);
system("PAUSE");
return 0;
}
補充說明(Supplement):
先謝謝大家了(拜)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.248.77
→
01/08 03:13, , 1F
01/08 03:13, 1F
test.cpp
c:\users\michael\documents\visual studio
2010\projects\test\test\test.cpp(8): error C2064: 詞彙不等於使用 3 引數的函式
c:\users\michael\documents\visual studio
2010\projects\test\test\test.cpp(25) : 請參閱所要編譯的函式 樣板 具現化 'Q
happy<int>(Q,Q,Q)' 的參考
with
[
Q=int
]
c:\users\michael\documents\visual studio
2010\projects\test\test\test.cpp(8): error C2064: 詞彙不等於使用 3 引數的函式
c:\users\michael\documents\visual studio
2010\projects\test\test\test.cpp(26) : 請參閱所要編譯的函式 樣板 具現化 'Q
happy<double>(Q,Q,Q)' 的參考
with
[
Q=double
]
c:\users\michael\documents\visual studio
2010\projects\test\test\test.cpp(8): error C2064: 詞彙不等於使用 3 引數的函式
c:\users\michael\documents\visual studio
2010\projects\test\test\test.cpp(27) : 請參閱所要編譯的函式 樣板 具現化 'Q
happy<char>(Q,Q,Q)' 的參考
with
[
Q=char
]
※ 編輯: fireslayer 來自: 140.113.248.77 (01/08 03:16)
抱歉有點亂 還有我看不太懂甚麼是
請參閱所要編譯的函式 樣板 具現化 'Q happy<char>(Q,Q,Q)' 的參考
這不是我寫的嗎??
※ 編輯: fireslayer 來自: 140.113.248.77 (01/08 03:18)
→
01/08 03:17, , 2F
01/08 03:17, 2F
→
01/08 03:18, , 3F
01/08 03:18, 3F
喔喔我知道了 內建的max函式只能求兩個varibles的最大值
平常用的太習慣了沒有注意到 謝謝詹姆士大XD(拜)
※ 編輯: fireslayer 來自: 140.113.248.77 (01/08 03:22)
→
01/08 03:20, , 4F
01/08 03:20, 4F
恩 謝謝提醒=口=
※ 編輯: fireslayer 來自: 140.113.248.77 (01/08 03:22)
→
01/08 03:23, , 5F
01/08 03:23, 5F
萬分感謝!!!!
※ 編輯: fireslayer 來自: 140.113.248.77 (01/08 03:30)
→
01/08 03:50, , 6F
01/08 03:50, 6F
請問是要加在哪邊
是每個cout.cin這些都要變成std::cout std::cin嗎?
※ 編輯: fireslayer 來自: 140.113.248.77 (01/08 14:01)
→
01/08 14:04, , 7F
01/08 14:04, 7F
→
01/08 14:04, , 8F
01/08 14:04, 8F
→
01/08 14:05, , 9F
01/08 14:05, 9F
謝謝!!
※ 編輯: fireslayer 來自: 140.113.248.77 (01/08 22:39)