Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.