This is my main working class that does all the high level operations:
class Image
{
public:
Image();
Image(const Image& copy);
~Image();
void loadimage(string filename);
void saveimage(string filename);
Image superimpose(const Image& ontop, Color mask);
int getwidth();
int getheight();
Image operator=(const Image&);
protected:
vector< vector<Color> > pixels;
int width;
int height;
ImageLoader* loader;
};
It has a copy constructor:
Image::Image(const Image& copy)
{
width = copy.width;
height = copy.height;
loader = copy.loader;
pixels = copy.pixels;
}
and an overloaded operator= method:
Image Image::operator=(const Image& other)
{
width = other.width;
height = other.height;
loader = other.loader;
pixels = other.pixels
// Return this instance
return *this;
}
The destructor is:
Image::~Image()
{
delete loader;
}
The loadimage() method created a new dynamically allocated loader to appear:
if(magic_number == "P3")
{
loader = new P3Loader;
}
else if (magic_number == "P6")
{
loader = new P6Loader;
}
else
{
exit(1); // If file is of an inappropriate format
}
When I run the program, it hangs.
EDIT: The post has been edited to reflect the problem. Refer to Praetorian's solution that fixed the problem.