QCache和std :: shared_ptr

时间:2015-10-15 20:26:53

标签: c++ qt c++11 smart-pointers

有人可以给我一个暗示这个错误的提示:

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

QCache看起来像这样:

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

我尝试插入这样的元素:

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

感谢您的帮助。

1 个答案:

答案 0 :(得分:3)

刚看了QCache API,由于我的猜测是正确的,我会将其作为答案发布(希望提供赞成!)。

insert()的签名为bool QCache::insert(const Key & key, T * object, int cost = 1)。此外,API提到QCache从那一刻开始拥有指针这一事实,因此您根本不需要shared_ptr。相反,您应该插入将由QCache管理的原始指针。