Jump to content
  • Advertisement
Sign in to follow this  
yoshscout

no downside to smart pointers - don't lose "this" keyword

This topic is 4095 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

[Edit] i was wrong one downside is that you must pass the smart pointer always. in essence, this takes away the "this" keyword. example where i learned this(psuedocode) class Resource has std::list of weak ptrs to Instances class Instance has smart pointer to Resource has a member function to change the Resource if i want to assign a resource to Instance, i can not make instance intelligently pass itself to Resource(and even more important resource pass itself to other subsystems ie loading queue) without sending it the smart pointer of itself it is possible by doing AssignResource(ResourcePtr pRes, InstancePtr pThis); but i have never had to pass an object a pointer to itself so this is really ... fairly ugly i think by removing "this" u really lose a powerful keyword [Edited by - yoshscout on September 29, 2007 3:58:11 PM]

Share this post


Link to post
Share on other sites
Advertisement
It's perfectly possible to use the this keyboard. If you're using Boost's smart pointers, use the shared_from_this idiom. It's in the documentation.

Share this post


Link to post
Share on other sites
well it seems to me like a pretty good design for a resources to be queued to the background loading thread as objects are created that require the resource(it is more container like)

additionally when no objects are using a resource you have a way of catching that in the objects destructor(again more container like)

the only ways to solve this is to keep a weak ptr filled in by the smart pointer the object was created by, or to change the design to have a 3rd class baby sit all of this(constructs the object - passes it to resource - queues it to resource loader if needed - returns object)

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
It's perfectly possible to use the this keyboard. If you're using Boost's smart pointers, use the shared_from_this idiom. It's in the documentation.


awesome

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!