2013-04-11 38 views
2

我有一個std :: pair聲明顯示在下面的代碼片段和g ++問題下面的第152行編譯錯誤說「錯誤:錯誤的模板參數數量(1,應該是2)「。我是這個std :: pair的新手,我想知道我做錯了什麼。所以提到的行號已被標記在下面的代碼片段中。謝謝。std :: pair - error:錯誤的模板參數數量

std::vector< 
       std::pair<EndPointAddr* requesterServiceAddr, 
         EndPointAddr* requestedServiceAddr>* //LINE 152 is HERE 
      > mServiceSubscriptionsList; 


    In file included from ServiceRegistrar.hpp:8:0, 
        from ServiceRegistrar.cpp:7: 
    ../control_api/ServiceRegistrarAPI.hpp:152:95: error: wrong number of template arguments (1, should be 2) 
    ........ 
    ....... 
    ../control_api/ServiceRegistrarAPI.hpp:153:14: error: template argument 1 is invalid 
    ../control_api/ServiceRegistrarAPI.hpp:153:14: error: template argument 2 is invalid 
    In file included from ../control_api/ServiceRegistrarAPI.cpp:5:0: 
+0

「'EndPointAddr * requesterServiceAddr'」 - 不要給它一個名字,'std :: pair'只需要類型。此外,太多doggamn指針! – Xeo 2013-04-11 16:32:01

回答

2

std::pair只需要類型在聲明。

std::vector< 
      std::pair<EndPointAddr*, 
        EndPointAddr* >* //LINE 152 is HERE 
     > mServiceSubscriptionsList; 
2

你需要把一個類型作爲模板參數,而不是一個變量:

std::vector< std::pair<EndPointAddr*, EndPointAddr*>* >