Skip to content

Instantly share code, notes, and snippets.

@tom76kimo
Created September 21, 2018 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tom76kimo/e00740b34607485d1844090ce068bde2 to your computer and use it in GitHub Desktop.
Save tom76kimo/e00740b34607485d1844090ce068bde2 to your computer and use it in GitHub Desktop.
class ImagePtr {
public:
ImagePtr(const char* imageFile);
virtual ~ImagePtr();
virtual Image* operator->();
virtual Image& operator*();
private:
Image* Loadlmage();
private:
Image* _image;
const char* _imageFile;
};
ImagePtr::ImagePtr (const char* thelmageFile) {
_imageFile = thelmageFile;
_image = 0;
}
Image* ImagePtr::Loadlmage () {
if (_image ==0) {
_image = LoadAnlmageFile(_imageFile);
}
return _image;
}
//===== Look at here =========
Image* ImagePtr::operator-> () {
return Loadlmage();
}
Image& ImagePtr::operator* () {
return *LoadImage();
}
// =============================
ImagePtr image = ImagePtr("anlmageFileName");
image->Draw(Point(50, 100));
// (image.operator->())->Draw(Point(50, 100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment