Jump to content
  • Advertisement
Sign in to follow this  
UncleRemus

Constructor question

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

Hello, suppose you have something like this :
class cA
{
private:
	object * attrib;

public:
	cA(object * param)
	{
		attrib = param;
	}

	virtual ~cA()
	{
	}

}



cA test = new cA( new object() );


How will the attrib get deleted ? Should I consider using a boost::shared_ptr here and just delete it in the destructor ?

Share this post


Link to post
Share on other sites
Advertisement
If you're only ever going to be allocating new memory for object, put the call to new inside the constructor. However, I doubt that's how you're going it, so I'd say allocate the memory before calling the constructor, pass the pointer to the dynamic array to the constructor, and free the memory externally. A smart pointer is likely a good route.

That's my best guess, as I don't really know what it is this class does.

Share this post


Link to post
Share on other sites

Hey,

Thanks for the quick reply. The question was more a generic design thing.
I'm writing a procedural texture generation tool and I would use such a class to apply effects to the texture. For most effects I just pass a pointer to the texture in the Apply method and fill the effect parameters in the constructor.

For effects where I combine textures however, I would need to pass a texture to the constructor. I think I'll go for smart pointers though, just to keep all options open for the caller. A good opportunity to learn some boost, I guess.

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!