question for pointer

This is a discussion on question for pointer within the C++ Programming forums, part of the General Programming Boards category; i just have a question are this the same if not why or why not. Code: x.y // member y ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    96

    question for pointer

    i just have a question are this the same if not why or why not.


    Code:
    x.y   // member y of object by x
    x->y  menber y of object by x but am i passing by reference right?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,652
    No, x->y is equivalent to (*x).y, i.e., member y of object pointed to by x.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    Location
    United Kingdom
    Posts
    195
    When you use x.y, x is an object instance, but in the case x->y then x is a pointer to an object you have created and you are accessing member y through the pointer to that object rather than through the object instance itself.

    x->y is the same as (*x).y
    and
    x.y is the same as (&x)->y

    Edit: Laserlight is quick off the button when it comes to answering questions, lol.
    Last edited by Swarvy; 10-28-2010 at 10:22 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question bout my work
    By SirTalksAlots in forum C Programming
    Replies: 4
    Last Post: 07-18-2010, 03:23 PM
  2. A question about a question
    By hausburn in forum C++ Programming
    Replies: 3
    Last Post: 04-25-2010, 05:24 AM
  3. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

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