【问题标题】:std::pair - error: wrong number of template argumentstd::pair - 错误:模板参数的数量错误
【发布时间】:2013-04-11 16:29:05
【问题描述】:

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

  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:

【问题讨论】:

  • "EndPointAddr* requesterServiceAddr" - 不要给它起名字,std::pair 只想要类型。此外,太多的教条指针!

标签: c++ std-pair


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-25
      • 1970-01-01
      • 2017-07-21
      • 2019-06-08
      相关资源
      最近更新 更多