CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17
  1. #16
    Join Date
    Aug 2005
    Location
    LI, NY
    Posts
    576

    Re: private members not so private.

    Quote Originally Posted by Peter_APIIT
    What is conclusion about this topic ? Why this will happen ?
    The conclusion is that C++ will not keep you from shooting yourself in the foot if you are hell-bent on doing so. Compiler rules exist to keep sane programmers from making mistakes, not to keep insane programmers from deliberately breaking them. I think Graham hit the nail on the head with this earlier.

    It is worth mentioning that unions may not contain non-POD types, so this "method" of accessing private data doesn't apply to the vast majority of classes. You can still use pointers to access the data, but that's not the point. The point is don't do it.
    - Alon

  2. #17
    Join Date
    Nov 2003
    Posts
    1,405

    Re: private members not so private.

    Quote Originally Posted by Peter_APIIT
    What is conclusion about this topic ? Why this will happen ?
    The conclusion is that the OP hasn't accessed a private class member at all. He has modified the internal (compiler dependent) representation of an object in memory.

    In C++ this is possible because you have language access to memory. A pointer is a memory address. It's just to start reading and writing to your hearts desire. If you want to do the same in Java you could serialize the object to file, change it there, and then read it back.

    As I expressed it in my previous post; The OP hasn't bypassed class privacy, he has raped an object.
    Last edited by _uj; September 8th, 2008 at 01:14 PM.

Page 2 of 2 FirstFirst 12

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