What does .* and ->* do?

This is a discussion on What does .* and ->* do? within the C++ Programming forums, part of the General Programming Boards category; Im wonderin what do those operators do? My book is lazy and wont tell me....

  1. #1
    Back after 2 years Panopticon's Avatar
    Join Date
    Dec 2002
    Posts
    262

    What does .* and ->* do?

    Im wonderin what do those operators do? My book is lazy and wont tell me.
    I AM WINNER!!!1!111oneoneomne

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by vVv
    Probably because there is no such operator in C++.
    Actually, they are.

    They actually do consider .* and ->* single operators.

    All they do are derefernce and "attach" a member function pointer to an object directly or through a pointer to an object (respectively). I personally always just think of .* as 2 operators: the . operator and the * operator (same for ->*), but they actually are single operators of their own.

    Example usage:

    Code:
    #include<iostream>
    
    class An
    {
    public:
        void SomeFunction() const;
    };
    
    void An::SomeFunction() const
    {
        std::cout << "SomeFunction\n";
    }
    
    int main()
    {
        void (An::*MemFunc)() const = An::SomeFunction;
        An Object,
          *ObjectPointer = &Object;
        (Object.*MemFunc)();
        (ObjectPointer->*MemFunc)();
        return 0;
    }
    Last edited by Polymorphic OOP; 01-05-2003 at 02:49 AM.

  3. #3
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by vVv
    OK, ISO/IEC 14882-1998 agrees with ``them''.
    Ha, yeah -- it's so much easier to just say "them."

  4. #4
    Back after 2 years Panopticon's Avatar
    Join Date
    Dec 2002
    Posts
    262
    Yeah thanx Polymorphic dude
    I AM WINNER!!!1!111oneoneomne

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