overloading operator ->*

Discussion in 'C++' started by n2xssvv g02gfr12930, Nov 25, 2005.

  1. Does anyone know of an example of overloading operator ->*

    Cheers

    JB
    n2xssvv g02gfr12930, Nov 25, 2005
    #1
    1. Advertising

  2. n2xssvv g02gfr12930 wrote:
    >
    > Does anyone know of an example of overloading operator ->*


    Austria C++ has "smart pointers" that do this.

    The operator needs to return a pointer.

    struct T
    {
    int x;
    };

    struct X
    {

    T * m_ptr;

    T * operator->()
    {
    return m_ptr;
    }
    };
    Gianni Mariani, Nov 25, 2005
    #2
    1. Advertising

  3. Gianni Mariani wrote:
    > n2xssvv g02gfr12930 wrote:
    >
    >>
    >> Does anyone know of an example of overloading operator ->*

    >
    >
    > Austria C++ has "smart pointers" that do this.
    >
    > The operator needs to return a pointer.
    >
    > struct T
    > {
    > int x;
    > };
    >
    > struct X
    > {
    >
    > T * m_ptr;
    >
    > T * operator->()
    > {
    > return m_ptr;
    > }
    > };


    That's not an example of overloading 'operator ->*' but 'operator ->'.

    JB
    n2xssvv g02gfr12930, Nov 26, 2005
    #3
  4. ben wrote:
    > n2xssvv g02gfr12930 wrote:
    >
    >>
    >> Does anyone know of an example of overloading operator ->*
    >>
    >> Cheers
    >>
    >> JB

    >
    >
    >
    > How do you overload two operators at the same time???
    > Ben


    ->* is only one operator, just like .*

    The are used with 'pointers to members'. Look them up in your favourite
    C++ book.

    john
    John Harrison, Nov 26, 2005
    #4
  5. n2xssvv g02gfr12930

    ben Guest

    n2xssvv g02gfr12930 wrote:
    >
    > Does anyone know of an example of overloading operator ->*
    >
    > Cheers
    >
    > JB



    How do you overload two operators at the same time???
    Ben
    ben, Nov 26, 2005
    #5
  6. n2xssvv g02gfr12930

    Protoman Guest

    What does ->* do? and what does .* do?
    Protoman, Nov 26, 2005
    #6
  7. n2xssvv g02gfr12930 wrote:

    >
    > That's not an example of overloading 'operator ->*' but 'operator ->'.


    Yep, you're right. My mistake.


    struct S
    {
    int z;

    int & operator ->* ( int S::* const & x )
    {
    return this->*x;
    }

    };

    struct Y
    {
    int z;

    template <typename T>
    T & operator ->* ( T Y::* const & x )
    {
    return this->*x;
    }

    };

    int main()
    {
    S s;
    int S::* pmz = &S::z;

    s->*( pmz ) = 3;

    Y y;
    int Y::* pmy = &Y::z;

    y->*( pmy ) = 3;
    }
    Gianni Mariani, Nov 26, 2005
    #7
    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. John Smith
    Replies:
    2
    Views:
    407
    Ivan Vecerina
    Oct 6, 2004
  2. Replies:
    11
    Views:
    707
    James Kanze
    May 16, 2007
  3. hurcan solter
    Replies:
    3
    Views:
    708
    Cholo Lennon
    Aug 29, 2007
  4. Replies:
    11
    Views:
    538
  5. Replies:
    2
    Views:
    292
Loading...

Share This Page