operator->

This is a discussion on operator-> within the C++ Programming forums, part of the General Programming Boards category; Directly from the auto_ptr class of the <memory> header in my STL implementation: Code: /** * @brief Smart pointer dereferencing. ...

  1. #16
    Registered User
    Join Date
    May 2003
    Posts
    161
    Directly from the auto_ptr class of the <memory> header in my STL implementation:


    Code:
      /**
       *  @brief  Smart pointer dereferencing.
       *
       *  This returns the pointer itself, which the language then will
       *  automatically cause to be dereferenced.
      */
      element_type*
      operator->() const throw() { return _M_ptr; }

  2. #17
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Code:
    template<typename Y>
    class UselessExample
    {
    public:
       Y* operator ->() { return ptr_;}
       Y& operator *() { return *ptr_;}
    private:
       Y* ptr_;
    };
    There you go.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #18
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Stroustrup's C++PL, Special Edition, p. 262.

    The only one's which cannot be redefined are '::', '.', and '.*'. Of course, '?:' can't be either, but its sort of a weird 'operator' anyways.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21