Thread: What's the use of .* operator in c++?

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    7

    What's the use of .* operator in c++?

    hi everybody,

    What's the use of .* operator in c++?
    please explain this concept with an example.

  2. #2
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    These are two different operators.

    The asterisk dereferences a pointer. (Gets-to the data pointed-to by the pointer.)

    The period/dot-operator accesses either a data member of a structure, or a data-member or member-function of an object.

    So, together they would access either member-data or a member function via a pointer.

    Code:
    X = DougDbug.*pAge;    //X = Doug's age
    Y = avil_beloved.*pAge;  // Y = Avil's age
    Last edited by DougDbug; 10-18-2004 at 01:22 PM.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    311
    nitpick.* is a syntax error, *grib.pAge de-references what member pointer pAge references. This is why you have -> if grib was a pointer to a structure then you would need the ugly syntax *(*pGrib).pAge

  4. #4
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Quote Originally Posted by DougDbug
    These are two different operators.
    No.

    Here's a page I found explaining this operator and the ->* operator thoroughly.
    http://linuxquality.sunsite.dk/articles/memberpointers/
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  5. #5
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511
    Sang-drax is correct

    Pointer to member provides only an offset into an object of the member's class at which that member can be found.

    Can't be overloaded as well.

    Mr. C.
    Mr. C: Author and Instructor

  6. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    78

    pointer

    that is a pointer which references to contents of another variables address for instance

    int *p
    p=&a;

    which means that p references the contents of the variable a's address.

Popular pages Recent additions subscribe to a feed