Professional Documents
Culture Documents
Opaque Pointer: Start Your Coding Journey Now!
Opaque Pointer: Start Your Coding Journey Now!
ref=lbp
Data Structures Algorithms Interview Preparation Topic-wise Practice C++ Java Python
Opaque Pointer
Difficulty Level : Medium ● Last Updated : 03 Apr, 2019
Following pointer is opaque. One can’t know the data contained in STest
structure by looking at the definition.
pSTest = NULL;
Let’s say we are working on an app to deal with images. Since we are
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge
Start Your
living Coding
in a world Journey
where Now!
that you have read and understood our Cookie Policy &Login
everything is moving to cloud and devices are Privacy Policy Register
1 of 7 12-02-2022, 07:13 pm
Opaque Pointer - GeeksforGeeks https://www.geeksforgeeks.org/opaque-pointer/?ref=lbp
and apple platforms. So, it would be nice to have a good design which is
robust, scalable and flexible as per our requirements. We can have
shared code which would be used by all platforms and then different
end-point can have platform specific code.
To deal with images, we have a CImage class exposing APIs to deal with
various image operations (scale, rotate, move, save etc).
Since all the platforms will be providing same operations, we would
define this class in a header file. But the way an image is handled might
differ across platforms. Like Apple can have different mechanism to
access pixels of an image than Windows does. This means that APIs
might demand different set of info to perform operations. So to work on
shared code, this is what we would like to do:
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge
Start Your Coding Journey Now!
// Constructor
CImage::CImage()
andhave
that you destructor our Cookie Policy &Login
for CImage
read and understood Privacy Policy Register
{
Got It !
2 of 7 12-02-2022, 07:13 pm
Opaque Pointer - GeeksforGeeks https://www.geeksforgeeks.org/opaque-pointer/?ref=lbp
InitImageInfo();
}
CImage::~CImage()
{
// Destroy stuffs here
}
struct SImageInfo
{
// Windows specific DataSet
};
void CImage::InitImageInfo()
{
pImageInfo = new SImageInfo;
// Initialize windows specific info here
}
void CImage::Rotate()
{
// Make use of windows specific SImageInfo
}
struct SImageInfo
{
// Apple specific DataSet
};
void CImage::InitImageInfo()
{
pImageInfo = new SImageInfo;
3 of 7 12-02-2022, 07:13 pm
Opaque Pointer - GeeksforGeeks https://www.geeksforgeeks.org/opaque-pointer/?ref=lbp
Please note that the above explained example is one way of doing this.
Design is all about discussion and requirement. A good design is
decided taking many factors into account. We can also have platform
specific classes like CImageWindows, CImageApple and put all platform
specific code there.
Like 43
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge
Start Your Coding Journey Now!
that you have read and understood our Cookie Policy &Login
Privacy Policy Register
Got It !
4 of 7 12-02-2022, 07:13 pm
Opaque Pointer - GeeksforGeeks https://www.geeksforgeeks.org/opaque-pointer/?ref=lbp
Previous Next
R ECO M M E N D E D A RT I C L E S Page : 1 2 3
28, Aug 19
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge
Start Your Coding Journey Now!
that you have read and understood our Cookie Policy &Login
Privacy Policy Register
Article Contributed By : Got It !
5 of 7 12-02-2022, 07:13 pm
Opaque Pointer - GeeksforGeeks https://www.geeksforgeeks.org/opaque-pointer/?ref=lbp
GeeksforGeeks
Improved By : xinxiao2009
Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.
Load Comments
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge
Start Your Coding Journey Now!
that you have read and understood our Cookie Policy &Login
Privacy Policy Register
Got It !
6 of 7 12-02-2022, 07:13 pm
Opaque Pointer - GeeksforGeeks https://www.geeksforgeeks.org/opaque-pointer/?ref=lbp
feedback@geeksforgeeks.org
Company Learn
About Us Algorithms
Contact Us CS Subjects
CSS Internships
JavaScript Videos
Bootstrap
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge
Start Your Coding Journey Now!
that you have read and understood our Cookie Policy &Login
Privacy Policy Register
Got It !
7 of 7 12-02-2022, 07:13 pm