问题描述
我有一个shared_ptr映射的指针。我想在地图中找到一个特定的元素并将其提取。我想知道如何找出我要寻找的元素,以及如何找到该元素(如果存在)。我能够得到这么多,但我不确定-评论中的问题:)
提前道歉,我是c ++新手,我正在尝试学习代码,以实现自己想要的功能...
price_manual.h
typedef std::shared_ptr<std::map<std::string,std::shared_ptr<ExtendedPrice>>> ExtendedPriceMapPtr;
class PriceManual : public Manual
{
public:
PriceManual(const std::shared_ptr<Action> action_p,ExtendedPriceMapPtr extendedPriceMap_p);
void print();
private:
ExtendedPriceMapPtr d_extendedPriceMap_p;
}
price_manual.cpp
PriceManual::PriceManual(const std::shared_ptr<Action> action_p,ExtendedPriceMapPtr extendedPriceMap_p)
: Manual(action_p),d_extendedPriceMap_p(extendedPriceMap_p)
void ExtendedPriceMap::print(const Something& something)
{
if (d_extendedPriceMap_p->find("name") != d_extendedPriceMap_p->end())
// Is this a correct way of finding an element and making sure it exists?
{
// I would like to do something like
// std::shared_ptr<ExtendedPrice> ext_price_p = d_extendedPriceMap_p["name"];
// const ExtendedPrice extended_price = ext_price_p->extended_price();
// to eventually get that extended_price.
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)