boost::shared_ptr assignment...

This topic is 2124 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

 vector<shared_ptr<D3DXMATRIX>> boneMatrixPtrs; if(b != NULL)boneMesh->boneMatrixPtrs.push_back(new shared_ptr<D3DXMATRIX>(&b->combinedTransform)); 

and combined with offset transform later on.
Wish you would know what I am talking about.
This just doesn't work

[Translated]
error C2664: 'void std::vector<_Ty>::push_back(_Ty &&)' : Cannot convert the variable from 'std::tr1::shared_ptr<_Ty> *' to 'std::tr1::shared_ptr<_Ty> &&' q:\perfectsim 24-8-2012 [test2]\perfectsim v4.0\perfectsim v4.0\cmesh.cpp 384 1 PerfectSim V4.0

Share on other sites
The vector stores shared_prt but you're passing it a pointer to a shared_ptr. To fix the error itself you need to drop the new because the vector doesn't store pointers to the smart pointer; but more importantly, is there a reason you're storing trivial objects such a matrices in a shared pointer in the first place?

Share on other sites
new shared_ptr<D3DXMATRIX> returns a pointer to a shared_ptr. If you just want to put a shared_ptr into the vector, you should be able to just get rid of the 'new' (if my understanding of C++ constructors is still intact).

Share on other sites
Thanks you guys.
Bob: I want to free up from the hassle of managing raw pointers. Just lazy

Share on other sites
Let me rephrase the question; why are you storing matrices by any kind of pointer and not just directly by value?

Share on other sites
As far as I know, boneMatrixPtrs have to be altered when combinedTransforms are altered.
So they are linked. I think that's why

Share on other sites
I can't count how many ways we need a pointer
1) Change when the parent pointer changes
2) Size too large by value
3) contains an array of something
That's all?

Share on other sites
In case I use a shared_ptr, do I eliminate its destructor?
Thanks
Jack

Share on other sites
I see some problems with your motivation for storing pointers (which in itself is not wrong, I accept your reason) and the fact that it stores smart pointers. Is combinedTransforms a value of type D3DXMATRIX? Is the idea to take the address of that matrix and put it in a vector so that you can keep a vector of pointers that are linked to the actual combined transforms stored somewhere else?

Assuming that is the case, you're going to have a problem: the shared pointers stored in the vector will automatically release the pointer they hold when the vector is released, but since you're storing pointer to values the pointers must not be released. The lifetime of the objects being pointed to is managed by the object holding the original matrices, and the ownership cannot be transferred to the smart pointers.

Assuming, again, that this is the case, you actually want plain pointers in the vector instead of smart pointers. Since you don't have ownership or lifetime management problems with the pointers in the vector, you won't have any problems with just letting the vector release itself.

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
18

• 11
• 12
• 9
• 12
• 37
• Forum Statistics

• Total Topics
631420
• Total Posts
2999990
×