std :: pair - 错误:模板参数错误

时间:2013-04-11 16:29:06

标签: c++ std-pair

我有一个std :: pair声明显示在下面的代码片段和g ++问题下面的编译错误第152行说“错误:错误的模板参数数量(1,应该是2)”。我是这个std :: pair的新手,我想知道我做错了什么。所提到的行号已在下面的代码段中标记。感谢。

  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:

2 个答案:

答案 0 :(得分:2)

您需要将类型作为模板参数,而不是变量:

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

答案 1 :(得分:2)

std::pair只需要声明中的类型

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