operator->(), making one object look like another

This is a discussion on operator->(), making one object look like another within the C++ Programming forums, part of the General Programming Boards category; Why can't I do this? It's used in this example: http://www.parashift.com/c++-faq-lit...html#faq-16.21 Or am I missing the point in overloading operator->? ...

  1. #1
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361

    operator->(), making one object look like another

    Why can't I do this? It's used in this example: http://www.parashift.com/c++-faq-lit...html#faq-16.21 Or am I missing the point in overloading operator->?
    Code:
    struct a
    {
    	a() : one(1), two(2) {};
    	int one;
    	int two;
    };
    
    class b
    {
    public:
    	b() {};
    	a operator->() { return m_a; }
    private:
    	a m_a;
    };
    
    int main()
    {
    	b myb;
    
    	cout << myb->one;
    	return 0;
    }

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Posts
    5,453
    Rolling out the smart pointers - eh?

    >>a * operator->() { return &m_a; }
    Code:
    int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000
    <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan
    (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000
    )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Object reference not set to instance of an object
    By patricio2626 in forum C++ Programming
    Replies: 6
    Last Post: 10-26-2006, 08:12 AM
  2. Linked List Templates and Object Types
    By ventolin in forum C++ Programming
    Replies: 10
    Last Post: 06-16-2004, 12:05 PM
  3. Set Classes
    By Nicknameguy in forum C++ Programming
    Replies: 13
    Last Post: 10-31-2002, 01:56 PM
  4. Set Classes
    By Nicknameguy in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2002, 07:40 PM
  5. Testing object pointer for null
    By VanJay011379 in forum C++ Programming
    Replies: 4
    Last Post: 07-24-2002, 10:51 AM

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