Bypass the overload of the address-of operator

Discussion in 'C++' started by Tomás Ó hÉilidhe, Jan 15, 2008.

  1. I can recall a little trick for getting the address of an object and
    bypassing any user-defined overload of the addressof operator. I think it
    was something like:

    T *p = reinterpret_cast<T*>( &reinterpret_cast<char&>(obj) );

    Is that it exactly, or are people using something else?

    --
    Tomás Ó hÉilidhe
     
    Tomás Ó hÉilidhe, Jan 15, 2008
    #1
    1. Advertisements

  2. Tomás Ó hÉilidhe

    Guest

    Tomás Ó hÉilidhe wrote:

    >
    > I can recall a little trick for getting the address of an object and
    > bypassing any user-defined overload of the addressof operator. I think it
    > was something like:
    >
    > T *p = reinterpret_cast<T*>( &reinterpret_cast<char&>(obj) );
    >
    > Is that it exactly, or are people using something else?


    Almost:

    // stolen from Boost:
    template < typename T >
    T * address_of (T & t) {
    return (
    reinterpret_cast<T*>(
    & const_cast<char&>(
    reinterpret_cast<const volatile char &>( t ) ) ) );
    }



    Best

    Kai-Uwe Bux
     
    , Jan 15, 2008
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chumma Dede
    Replies:
    2
    Views:
    820
    Chumma Dede
    Feb 9, 2006
  2. Mr Smith
    Replies:
    7
    Views:
    726
    Mr Smith
    Feb 10, 2005
  3. Matthew Monopole

    overload operator -

    Matthew Monopole, Aug 8, 2003, in forum: C++
    Replies:
    1
    Views:
    596
    Jakob Bieling
    Aug 8, 2003
  4. Jakob Bieling

    Q: Overload operator new/delete

    Jakob Bieling, Aug 8, 2003, in forum: C++
    Replies:
    0
    Views:
    563
    Jakob Bieling
    Aug 8, 2003
  5. John Harrison
    Replies:
    1
    Views:
    2,104
  6. Paul Escherton

    Templatized operator () overload

    Paul Escherton, Nov 10, 2003, in forum: C++
    Replies:
    2
    Views:
    474
    tom_usenet
    Nov 10, 2003
  7. Piotre Ugrumov
    Replies:
    3
    Views:
    640
    Nick Hounsome
    Jan 25, 2004
  8. Ying-Chieh Liao

    function overload (not operator overload)

    Ying-Chieh Liao, Oct 11, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    462
    Sherm Pendley
    Oct 11, 2004
Loading...