【发布时间】:2014-10-17 12:53:01
【问题描述】:
我在尝试将我的地图转换为集合时遇到了一些问题 我得到了一个带有这个成员数据的“Chanson”对象:
std::map<std::string,Artiste*> m_interpretes;
这是我将*Artiste 添加到我的地图的方法:
void Chanson::addArtiste(Artiste* a) throw (ExceptionArtiste, ExceptionLangueIncompatible)
{
if(a!=NULL)
{
if(a->getLangue() == this->getLangue())
{
m_interpretes.insert(pair<string, Artiste*>(a->getNom(), a));
//m_interpretes[a->getNom()] = a;
}
else
{
throw ExceptionLangueIncompatible(a,this);
}
}
}
set<Artiste*> Chanson::getArtistes() const
{
//set<Artiste*> machin;
return set<Artiste*> (m_interpretes.begin(), m_interpretes.end());
}
由于这个功能,我得到了这个错误:
错误 C2664: 'std::pair<_ty1> std::set<_kty>::insert(Artiste *&&) : 不可能 de convertir le paramètre 1 de const std::pair<_ty1> en 'Artiste *&&' c:\program files (x86)\microsoft visual studio 11.0\vc\include\set 179 1
知道怎么解决吗?
【问题讨论】:
-
为什么要将指针存储在容器中?这似乎是等待发生的内存泄漏。
-
第二个问题:为什么要使用动态异常规范?它们会导致各种奇怪的事情发生并减慢您的代码速度,目前的一般建议是完全避免它们。
-
其实在最新的标准中,动态异常规范已经被弃用了。
-
@user2079303:实际上,它们在以前的标准中已被弃用!
-
@LightnessRacesinOrbit 好吧,它们仍然仍然被弃用,除非我错过了什么。