本文介绍了QCache和std :: shared_ptr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以给我提示此错误的提示:

Can someone give me please a hint for this error:

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

QCache看起来像这样:

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);

推荐答案


$ b解决方案

解决方案

刚刚看了QCache API,由于我的猜测是正确的,我将它作为一个答案(希望upvotes!)。

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

的签名是 bool QCache :: insert(const Key& key,T * object,int cost = 1) code>。此外,API提到了QCache从那一刻起拥有指针的事实,所以你根本不需要shared_ptr。相反,你应该插入由QCache管理的原始指针。

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.

这篇关于QCache和std :: shared_ptr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 13:07