c++ - std::pair - 错误:模板参数数量错误

标签 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:

最佳答案

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

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

关于c++ - std::pair - 错误:模板参数数量错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15954086/

相关文章:

c++ - 为什么不需要资格?

c++ - C++ STL 中的 std::list<std::pair> 和 std::map 有什么区别?

c++ - 如何在 C++ 中存储一对数字?

c++ - union 成员可能没有构造函数,但是 `std::pair` 可以吗?

c++ - Base64 转换器输出不正确

c++ - #define NULL nullptr 是否安全?

c++ - vector< pair<aStruct*,int>> 不可能?

c++ - memset 在 C++ 中的一对数组

c++ - 将视频文件插入vector时vector内存不足?

c++ - 使用 qt 的多客户端/服务器 tcp 应用程序