Sign in to follow this  

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

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

This topic is 3725 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this