Thread: question for pointer

  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
    28,413
    No, x->y is equivalent to (*x).y, i.e., member y of object pointed to by x.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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, 01:47 AM