Jump to content
  • Advertisement
Sign in to follow this  
lucky6969b

boost::shared_ptr assignment...

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

If you intended to correct an error in the post then please contact us.

Recommended Posts


vector<shared_ptr<D3DXMATRIX>> boneMatrixPtrs;

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


boneMatrixPtrs are linked to 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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!