如题 , 编译时总是说 [Error] ld returned 1 exit status (编译器dev c++)
`#include<iostream>
using namespace std;
template <typename t>
class CValue {
t data[5];
public:
CValue() {
cout<<"please input 5 numbers"<<endl;
for(int i = 0; i < 5; i++)
cin>>data[i];
}
friend t Max(CValue <t> &a);
friend t Min(CValue <t> &a);
};
template <typename t> t Max(CValue <t> &a) {
t x = a.data[0];
for(int i = 1; i < 5; i++)
if(x < a.data[1]) x = a.data[1];
return x;
}
template <typename t> t Min(CValue <t> &a) {
t min = a.data[0];
for(int i = 1; i < 5; i++)
if(min > a.data[1]) min = a.data[1];
return min;
}
int main() {
cout<<"整数对象a,";
CValue<int> a;
cout<<"浮点数对象b,";
CValue<float> b;
cout<<"整数元素对象a的元素最大值为:"<<Max(a)<<endl;
cout<<"整数元素对象a的元素最小值为:"<<Min(a)<<endl;
cout<<"浮点数元素对象b的元素最大值为:"<<Max(b)<<endl;
cout<<"浮点数元素对象b的元素最小值为:"<<Min(b)<<endl;
}
`
你需要实例化模板函数
friend t Max<>(CValue <t> &a)