QCache and std::shared_ptr

时光怂恿深爱的人放手 提交于 2019-12-12 03:22:40

问题


Can someone give me please a hint for this error:

no viable conversion from 'std::shared_ptr<Foo>' to 'std::__1::shared_ptr<Foo> *'

The QCache looks like this:

QCache<int, std::shared_ptr<Foo>> cache;

And I try to insert the element like this:

std::shared_ptr<Foo> foo;
cache.insert(23, foo);

Thanks for your help.


回答1:


Just looked into QCache API, and since my guess is correct, I will post it as an answer (with hopes for upvotes!).

Signature for insert() is bool QCache::insert(const Key & key, T * object, int cost = 1). Moreover, API mentions the fact that QCache owns the pointer from that moment on, so you do not need shared_ptr at all. Instead, you should insert raw pointer which will be managed by QCache.



来源:https://stackoverflow.com/questions/33157910/qcache-and-stdshared-ptr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!