當前位置:編程學習大全網 - 編程軟體 - c++編程,類模板相關問題

c++編程,類模板相關問題

給妳改了下:

#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;

}

  • 上一篇:以作文大王為題的小學作文
  • 下一篇:用vba做了壹個報表,每次打開都提示是否啟用宏,我是用wps版本,怎麽才能不顯示呢?
  • copyright 2024編程學習大全網