0

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.

adapto
  • 95
  • 1
  • 12

1 Answers1

3

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.

SergeyA
  • 61,605
  • 5
  • 78
  • 137
  • Thanks for the answer and the help. – adapto Oct 15 '15 at 20:44
  • The problem is, that I have a vector of shared_ptr and I want to put part of them to my QCache. What happens if I set the pointer to my cache but destroy the vector and the shared pointer in it? WIll the memory be released and my cache points to nowhere? – adapto Oct 22 '15 at 09:18
  • @adapto, you will have a corrupted program if you try to do this. You can't have the same pointer owned by two managers - QCache and shared_ptr. – SergeyA Oct 22 '15 at 13:28
  • That caused the confusion: http://stackoverflow.com/questions/33280524/qcache-and-qsharedpointer/ – Orest Hera Oct 22 '15 at 15:23