給妳改了下:
#include?<iostream>#include?<string>
using?namespace?std;
template?<class?T>?//class?T就行了,只要類型相關的
class?StringValuePair
{
private:?
string?astring;//是string,不是string*
T?adate;
public:?
StringValuePair(string?a,T?b);?
string?first();?
T?second();
};
template?<class?T>
StringValuePair<T>::StringValuePair(string?a,T?b)
{ astring=a;?adate=b;}?
template?<class?T>string?StringValuePair<T>::first()
{return?astring;}
template?<class?T>T?StringValuePair<T>::second()
{return?adate;}
int?main()
{?
StringValuePair<int>?svp("Hello",5);?
cout<<"Pair:"<<svp.first()<<'?'<<svp.second()<<'\n';?
return?0;
}