标准::make_pair: "cannot convert ‘int*’ to ‘std::pair<EndPointAddr*, EndPointAddr*>*’ in initial
std::make_pair: "cannot convert ‘int*’ to ‘std::pair<EndPointAddr*, EndPointAddr*>*’ in initialization"
在下面列出的函数中,我试图创建一个指向std::pair对象的指针,在此消息的底部显示编译错误(相关的行号已在下面的代码片段中标记)。你能告诉我这个代码有什么问题吗?谢谢。
void
XXX::addSubscription(EndPointAddr* ptrRequesterServiceAddr,
EndPointAddr* ptrRequestedServiceAddr)
{
//LINE 908 indicated in the g++ output starts HERE
std::pair<EndPointAddr*, EndPointAddr* > *thePair =
new std::make_pair(ptrRequesterServiceAddr, ptrRequestedServiceAddr);
mServiceSubscriptionsList.push_back(thePair);
}
编译输出: ../XXX.cpp:
In member function ‘void XXX::addSubscription(EndPointAddr*, EndPointAddr*)’:
../XXX.cpp:908:59: error: expected type-specifier
../XXX.cpp:908:59: error: cannot convert ‘int*’ to ‘std::pair<EndPointAddr*, EndPointAddr*>*’ in initialization
../XXX.cpp:908:59: error: expected ‘,’ or ‘;’
std::pair<EndPointAddr*, EndPointAddr* > *thePair =
new std::make_pair(ptrRequesterServiceAddr, ptrRequestedServiceAddr);
^^^^^^
应该std::pair<EndPointAddr*, EndPointAddr* > *thePair =
new std::pair<EndPointAddr*, EndPointAddr*>(ptrRequesterServiceAddr, ptrRequestedServiceAddr);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
std::make_pair
是一个函数。
std::pair
指针分配给函数。您需要使用constructor而不是make pair而不是std::make_pair
std::pair<EndPointAddr*, EndPointAddr* > *thePair =
new std::pair<EndPointAddr*, EndPointAddr* >(ptrRequesterServiceAddr, ptrRequestedServiceAddr);
您的示例代码没有显示mServiceSubscriptionsList
的类型,这将有助于了解。
试试这个:
void
XXX::addSubscription(EndPointAddr* ptrRequesterServiceAddr,
EndPointAddr* ptrRequestedServiceAddr)
{
//LINE 908 indicated in the g++ output starts HERE
std::pair<EndPointAddr*, EndPointAddr* > thePair =
std::make_pair(ptrRequesterServiceAddr, ptrRequestedServiceAddr);
mServiceSubscriptionsList.push_back(thePair);
}
相关文章:
- 是否需要删除包含对象的"pair"?
- 在我的代码中,获得最大的Pair Wise产品C++和输出并不总是正确的
- 为什么大多数 pair 实现默认不使用压缩(空基优化)?
- 对 pair<pair<int,int>pair<int,int unordered_map进行哈希处理>>
- 对的排序向量 (std::vector<pair<int, int>>) 按对的第一个元素搜索并更新第二个元素值
- 删除字符串中具有相同值的任何相邻字母"pair"
- 当我尝试定义这个向量时<pair<int , pair<int, int> > > vp(n)
- 如何从map<pair<string,int>,pair<string,Array>>中迭代和查找?
- ostream_iterator运算符=在pair<int,int>上失败,但在包装器类上工作。我不能为成对<>重载运算符<<吗?
- c++:在switch中使用std::pair的可能性
- 为什么 pair 在初始化中不需要类型
- 将从std::映射中获取的std::pair引用传递给接受std::对引用的函数
- pair的两个构造函数几乎相同,为什么不生成构建错误?
- 如何在一对集合的向量中插入元素?vector<pair<int,set<string>>>
- Hash for a std::pair, for use in an unordered_map
- 使用 pair<int、int> 或字符串作为 map<> 键,哪个更有效?
- 如何使用set<pair<int,int> >::iterator itrator it迭代set<pair<int,int> >st中的值?
- map<int,int>的*迭代器是什么?它不是pair<int,int>
- 在 c++ 中的 multiset<pair<int,int> > 中查找下限
- 标准::make_pair: "cannot convert ‘int*’ to ‘std::pair<EndPointAddr*, EndPointAddr*>*’ in initial