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. Advertising

  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. Advertising

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:
    710
    Chumma Dede
    Feb 9, 2006
  2. Mr Smith
    Replies:
    7
    Views:
    484
    Mr Smith
    Feb 10, 2005
  3. Matthew Monopole

    overload operator -

    Matthew Monopole, Aug 8, 2003, in forum: C++
    Replies:
    1
    Views:
    490
    Jakob Bieling
    Aug 8, 2003
  4. Piotre Ugrumov
    Replies:
    3
    Views:
    384
    Nick Hounsome
    Jan 25, 2004
  5. Ying-Chieh Liao

    function overload (not operator overload)

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

Share This Page