views:

196

answers:

4

What is an "opaque value" in C++?

+1  A: 

Check this link might help you -

http://calumgrant.net/opaque/index.html

Sachin Shanbhag
+2  A: 

That's similar to opaque pointer - a value that doesn't store data your code could interpret or provide access to data, but only identifies some other data. A typical example is a Win32 handle like HBITMAP bitmap handle - you can only pass it to relevant functions, but you can't do anything to the underlying bitmap directly.

sharptooth
The definition is ok, but I'd say that `HBITMAP` is an opaque *pointer* => it's just some kind of 32-bit pointer, not all the data of the bitmap packed in some opaque way.
Matteo Italia
+3  A: 

I assume (since your question did not give enough context to be sure) that you are referring to something like Opaque Pointers.

An example for an Opaque Pointer is FILE (from the C library):

#include <stdio.h>

int main()
{
    FILE * fh = fopen( "foo", "r" );
    if ( fh != NULL )
    {
        fprintf( fh, "Hello" );
        fclose( fh );
    }
    return 0;
}

You get a FILE pointer from fopen(), and use it as a parameter for other functions, but you never bother with what it actually points to.

DevSolar
That it's actually a pointer isn't important; opaque pointers are just opaque values that happen to be pointers.
Roger Pate
+2  A: 

FILE* is a good example of an opaque value. You don't use it directly; it's a single "blob" which you can't interpret or manipulate. Instead, you use a set of functions (fopen, fwrite, fprintf, etc.) which know how to manipulate it.

Being opaque in this way is common to many situations (and in many APIs) where you have a "magical" handle: a black box.

Roger Pate