#include<iostream>
using namespace std;
template <class T = int, class S = int>
class Pair {
public:
Pair() { }
Pair(T _first, S _second) : first(_first), second(_second) { }
void print();
private:
T first;
S second;
};
template<class T,class S>
void pair<T, S>::print()//问题1.为什么此处显示上面没有成员print.函数。
{
}
template <class T>
pair<int,int> search( T* vec, int n, const T &data)//问题2;它不是template<class T,class S>而且pair<int ,int>是什么意思呢?是表示它是属于pair<int,int>类的一个函数,可是函数里也没有声明?
{
pair<int, int>a;
vec = new T[n];
cout << "给数组元素赋值:" << endl;
for (int i = 0; i < n; i++)
cin >>vec[i];
int count = 0;
for (int i = 0; i < n; i++)
{
if (data==vec[i])
{
count++;
if (count==1)
{
a.first = i;
}
else if (count >= 2)
{
a.second = i;
}
}
else if(data!=vec[i])
vec[i] = -1;
}
cout << "第一次出现的位置为:" << a.first << endl;
if (a.second == a.first)
cout << "最后一次出现的位置和first一样也是:" << a.second << endl;
else
cout << "最后一次出现的位置为:" << a.second << endl;
return a;
}
int main()
{
}