When to use pointers in a class?

I

I V

Joe said:
class Image
{
public:
typedef unsigned int color_type;
Image(size_t width, size_t height);

It looks like Magick++ uses unsigned int, rather than size_t for height
and width specifications. Maybe your application ought to use the same?

[...]
Do I want to use references to the member objects here? Or pointers?
I'm having difficulties initializing the objects if they are references
and aren't passed in to the Image constructor.

Do you need to store the Geometry and ColorRGB objects at all? If
they're only being used as arguments to the Magick::Image constructor,
they can probably be local variables in your Image constructor.
Otherwise, you probably want to store the actual objects in your class
- neither reference nor pointer.

If the Magick::Image object has the same lifetime as your Image class,
then you probably want to store it directly in your class (again,
neither pointer nor reference). If the Magick::Image object is created
at some point after your Image object, or will be destroyed sometime
before your Image object, you should use a pointer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top