What does "->" operator mean?

This is a discussion on What does "->" operator mean? within the C++ Programming forums, part of the General Programming Boards category; Hi all; I was reading through the source code for Doom, and found an operator that I'm not familiar with. ...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    13

    Question What does "->" operator mean?

    Hi all;

    I was reading through the source code for Doom, and found an operator that I'm not familiar with. Despite some Google research, the only explanation I can find comes from a brief mention on Wikipedia saying that it's a Member by Pointer, with no other info.

    Does anyone know what this means? I'm very familiar with pointers, but don't know what Member by Pointer is. Sample code down below.

    In the source code, this operator is used all over the place, so it must be really important and useful.


    Thanks
    -Fremontknight

    Code:
     // set the entire zone to one free block
        mainzone->blocklist.next =
    	mainzone->blocklist.prev =
    	block = (memblock_t *)( (byte *)mainzone + sizeof(memzone_t) );
    
        mainzone->blocklist.user = (void *)mainzone;
        mainzone->blocklist.tag = PU_STATIC;
        mainzone->rover = block;
    	
        block->prev = block->next = &mainzone->blocklist;

  2. #2
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Edit: It's (*mainzone).blocklist, per laserlight. Sorry.

    (*foo).bar == foo->bar.

    Operator . binds tighter than operator *, per http://www.cppreference.com/operator_precedence.html. That's why it's (*foo).bar - to force * to come first, so to speak.
    Last edited by Lithorien; 05-07-2008 at 03:19 PM.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,593
    Actually, mainzone->blocklist is another way of saying (*mainzone).blocklist, not *mainzone.blocklist.

    *foo.bar is equivalent to *(foo.bar)
    foo->bar is equivalent to (*foo).bar
    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

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    No offense, but I don't think you're ready for the source code of Doom or any other advanced piece of software if you have to ask this.

  5. #5
    Registered User
    Join Date
    Jun 2007
    Posts
    13
    Lithorien and Laserlight: thanks for the good answers....thank you.

    medievalelks: You're acting like an idiot. Keep your useless put-downs to youself. In my life, I've always learned the most by stretching myself and reading real code to improve my knowledge.
    Remember, you were once just like me.

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Sorry for the bluntness of my remark, I just don't understand why so many people seem to eschew books when learning C++ nowadays. If we get one, we get a dozen questions daily that could be answered by looking at the most basic C++ book (or even online reference).

    Maybe it's a generational thing. I didn't have forums like this when I was learning, other than maybe Usenet. Even then, I'd ask questions as a last resort. Maybe that's where I got my acerbic nature - some of those Usenet guys can be *brutal* to newbies. Check out comp.lang.c++ for a few days and you'll think I'm Prince Charming :-)

  7. #7
    Registered User
    Join Date
    Jun 2007
    Posts
    13
    No prob medievalelks. Thanks to BitTorrent, I have about 200 C++ books, and I read them like a hungry insane man. Most books spend most time talking about classes and OOP, but don't talk about a nuance like the one I asked about. Not even my college textbook had mention of this question, and even Google didn't give a clear reply. Thank you, and to comp.lang.c++ I go. Take care...

  8. #8
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    Quote Originally Posted by Fremontknight1 View Post
    No prob medievalelks. Thanks to BitTorrent, I have about 200 C++ books, and I read them like a hungry insane man. Most books spend most time talking about classes and OOP, but don't talk about a nuance like the one I asked about. Not even my college textbook had mention of this question, and even Google didn't give a clear reply. Thank you, and to comp.lang.c++ I go. Take care...
    if you have an IDE the helpfiles are great for things like this. you just type in -> into the index and it will have an entry.

    things like style and the finer points of how to do things right...not so much. books are def. the way to go for that. unfortunately for me, i don't have the time at work ro read them or the desire to read them at home!

    i'm rather sophomoric for it.

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    > I have about 200 C++ books, and I read them like a hungry insane man.
    I find it astonishing that not one of them ever explained -> to you.
    More that you were in such a hurry that it never sank in when you saw it.

    It is perfectly possible to be "fact heavy" on C++ and still be utterly clueless on how to program.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,299
    Quote Originally Posted by Salem View Post
    > I have about 200 C++ books, and I read them like a hungry insane man.
    I find it astonishing that not one of them ever explained -> to you.
    I find it equally astonishing. One surely couldn't possibly not know what -> is if they've been programming for 2 weeks or more in one of the many programming languages that uses it.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  11. #11
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    Another term for it is the "indirection operator". I use it in classes when I return data members.

    Code:
    int Foo::getNumber() const
    {
       return this->m_Number;
    }
    Although technically you dont have to use the this* pointer to return data members, its just somthing I do.
    I'm just trying to be a better person - My Name Is Earl

  12. #12
    Banned
    Join Date
    Nov 2007
    Posts
    678
    but, the question is, why would anyone overload it for their class?

    medievalelks, how do i access comp.lang.c++ from Windows XP?
    sorry for such a stupid question, but i could never visit such sites(?) from my browser (Firefox or IE).

  13. #13
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,593
    but, the question is, why would anyone overload it for their class?
    Perhaps their class is a smart pointer class.
    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

  14. #14
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by manav View Post
    medievalelks, how do i access comp.lang.c++ from Windows XP?
    sorry for such a stupid question, but i could never visit such sites(?) from my browser (Firefox or IE).
    You can read Usenet groups using groups.google.com, but there is an almost unbearable influx of spam posted to the unmoderated ones (mostly from gmail users trying to get Google Ad hits, ironically). comp.lang.c++.moderated takes care of that problem for C++ programmers, but that also means your post has to be approved by a moderator, so it takes longer to get there. It also means FAQs aren't usually posted, nor are off-topic Windows, UNIX, etc. questions.

    There are also comp.lang.c, comp.object, lots of unix and windows programming groups, and just about anything you can think of. Usenet has been around long before the WWW and browsing, and the archive on groups.google.com goes back at least to the early 80s the last I checked. It's a great place to research.

  15. #15
    Banned
    Join Date
    Nov 2007
    Posts
    678
    thanks medievalelks!
    i can access the comp.lang.c++ now, i suppose it is a usenet group, never used it before, only heard of it, somewhere.

    i wanted to see them getting really angry at stupid newbie questions, i could not find such posts
    tell me if you come across such postings!

Page 1 of 2 12 LastLast
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