Thameera Senanayaka
Allion Technologies
aka Opaque Pointer or Cheshire Cat
And as private as possible.
class Image
{
public:
Image();
virtual ~Image();
int crop();
int setBrightness(int x);
private:
void resize(int x, int y);
unsigned char* imgData;
unsigned int w, h;
};
class Image
{
public:
Image();
virtual ~Image();
int crop();
int setBrightness(int x);
private:
class Impl;
Impl* _impl;
};
class Image::Impl
{
public:
int crop() { /* */ }
int setBrightness() { /* */ }
private:
void resize(int x, int y) { /* */ }
void* imageData;
unsigned int w, h;
};
Image::Image : _impl(new Impl()) {
}
Image::~Image {
if (_impl)
delete _impl;
}
int Image::crop() {
return _impl->crop();
}
int Image::setBrightness(int x) {
return _impl->setBrightness(x);
}
class Image
{
/* ... */
bool operator==(Image const& that) const { return _impl == that._impl; }
bool operator!=(Image const& that) const { return !operator==(that); }
operator bool() const { return impl_; }
/* ... */
};
class Image
{
public:
/* ... */
Image(const Image&); // copy ctor
Image& operator=(const Image&); // copy assignment operator
/* ... */
};
class Image
{
public:
/* ... */
private:
class Impl;
std::unique_ptr<Impl> _impl;
};