Created
September 21, 2018 03:48
-
-
Save tom76kimo/e00740b34607485d1844090ce068bde2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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