Std::pair语言 - error:模板参数数目错误

std::pair - error: wrong number of template argument

本文关键字:参数 数数 错误 error pair 语言 Std      更新时间:2023-10-16

我有一个std::pair声明,如下面的代码片段所示,在第152行编译错误下面的c++问题说"错误:模板参数数量错误(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:

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

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

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

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