Reputation: 11
I am writing a C++ program that reads a .bmp file and creates a dynamic 2D array of pixels[1], that represents the image. That information is stored in a class Image[2] instance.
So, I want to have functions that apply some color effects to the image, but I want only those functions to be able to access Image's private variables.
The Image class must be able to work without the color effects, so they cannot be functions of the class (inline), but the Image class, also do not have any getters nor setters. I thought of a friend functions, but that means that I must list each of those functions manually. I would be really grateful if someone could help me with my problem!
[1]
struct Pixel
{
unsigned char Red;
unsigned char Blue;
unsigned char Green;
unsigned char Unused;
};
[2]
class Image
{
public:
Image();
~Image();
bool Open(char*);
void Close();
bool Save();
private:
bool good;
Pixel** loadedImage;
char* filePath;
};
Upvotes: 1
Views: 76
Reputation: 129
It would seem that the most sensible way of doing it would be to make a class that has static members, and then make this class a friend class of Image. So, for e.g,
class Bitmap {
...
friend class ImageHandler;
}
class ImageHandler {
static void Manipulate();
}
void ImageHandler::Manipulate() {
// now you can access all of the private vars of Pixel.
}
void Pixel::SomeFunction() {
ImageHandler::Manipulate();
}
Upvotes: 1