CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: opaque pointer

  1. #1
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    opaque pointer

    Hello everyone,


    Opaque pointer must be a pointer points to inner (hidden to outside) struct or class?

    (refer to the C++ part)

    http://en.wikipedia.org/wiki/Opaque_pointer


    thanks in advance,
    George

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: opaque pointer

    This technique can have pointers point to anything. The key observation is that the user of the class must be unable to discern or exploit anything about the inner workings of an object given only a handle to it.

    In C, this might be done by handing back a void* which is only casted back to its actual type when it is passed to a function that knows what it is.

  3. #3
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Re: opaque pointer

    Thanks Lindley,


    So, not a mandatory requirement for the wrapped pointer member to point to some inner structure? Could be any other global defined structure?

    Quote Originally Posted by Lindley
    This technique can have pointers point to anything. The key observation is that the user of the class must be unable to discern or exploit anything about the inner workings of an object given only a handle to it.

    In C, this might be done by handing back a void* which is only casted back to its actual type when it is passed to a function that knows what it is.

    regards,
    George

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: opaque pointer

    It's just a design pattern. Such things don't really have requirements, per se, they're simply useful notions that people have figured out and documented.

    "We figured they was more guidelines, than actual rules."

  5. #5
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Re: opaque pointer

    Thanks Lindley,


    Could you provide a deinite answer (yes or no) whether the wrapper pointer member must point to inner types (structs/classes) please?

    Sometimes I am confused when people use this term.

    Quote Originally Posted by Lindley
    It's just a design pattern. Such things don't really have requirements, per se, they're simply useful notions that people have figured out and documented.

    "We figured they was more guidelines, than actual rules."

    regards,
    George

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: opaque pointer

    Quote Originally Posted by George2
    Thanks Lindley,


    Could you provide a deinite answer (yes or no) whether the wrapper pointer member must point to inner types (structs/classes) please?
    There is no definite answer. The pointer could point to NULL or just an int, or whatever the coder(s) decide it to point to.

    Are you planning to implement something using an opaque pointer?

    Regards,

    Paul McKenzie

  7. #7
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Re: opaque pointer

    Thanks Paul,


    Sorry I have not made myself understood. My question is, for the opaque pointer design "pattern", the member pointer should be pointed to some inner data structure or global/namespace level data structure or both ok?

    (ok I mean whether in this way, it could be called opaque pointer.)

    Quote Originally Posted by Paul McKenzie
    There is no definite answer. The pointer could point to NULL or just an int, or whatever the coder(s) decide it to point to.

    Are you planning to implement something using an opaque pointer?

    Regards,

    Paul McKenzie

    regards,
    George

  8. #8
    Join Date
    Apr 1999
    Posts
    27,449

    Re: opaque pointer

    Quote Originally Posted by George2
    Thanks Paul,


    Sorry I have not made myself understood. My question is, for the opaque pointer design "pattern", the member pointer should be pointed to some inner data structure or global/namespace level data structure or both ok?
    And my answer is still the same. It is up to the designer as to what the pointer points to.

    Regards,

    Paul McKenzie

  9. #9
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Re: opaque pointer

    Thanks Paul,


    Good to know it is not a must the pointer must be pointed to inner data structores for opaque pointer. :-)

    Quote Originally Posted by Paul McKenzie
    And my answer is still the same. It is up to the designer as to what the pointer points to.

    Regards,

    Paul McKenzie

    regards,
    George

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured