问题
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