Thread: A smal question(->? pointer?)

  1. #1
    Registered User wildex999's Avatar
    Join Date
    Feb 2006
    Posts
    15

    A smal question(->? pointer?)

    Hello, just a smal question, In some codes(In a tutoriao on this site too) I have seen this "->" with some kind of pointers, but I just can't understand what this do, what does it do? How do i use it? Please let me know, thanks ^_^

  2. #2
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    Code:
    string *blah;
    
    if((*blah).empty())
     return;
    Is the same as:

    Code:
    string *blah;
    
    if(blah->empty())
     return;
    The -> operator merely dereferences the pointer so it can call a class function like an object.
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  3. #3
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    it is a more visually pleasing way of accessing the members of a structure through a pointer .... see this example:


    Code:
    void print_person ( struct Person *pers )
    {
      printf ( "Name:   %s\n", pers->name );
      printf ( "Age:    %d years\n", pers->age );
      printf ( "Height: %.2f feet\n", pers->height );
    }
    which is a function used to access this struct:

    Code:
    struct Person {
      char *name;
      int age;
      struct Height 
    };
    it's all from the FAQ ... here just over half ways down
    Last edited by twomers; 02-21-2006 at 06:14 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Easy pointer question
    By Edo in forum C++ Programming
    Replies: 3
    Last Post: 01-19-2009, 10:54 AM
  2. char pointer to pointer question
    By Salt Shaker in forum C Programming
    Replies: 3
    Last Post: 01-10-2009, 11:59 AM
  3. a pointer to a function question..
    By transgalactic2 in forum C Programming
    Replies: 17
    Last Post: 10-21-2008, 11:47 AM
  4. A pointer question.
    By joenching in forum C++ Programming
    Replies: 7
    Last Post: 03-20-2008, 04:10 PM
  5. Simple pointer question
    By jayznz in forum C Programming
    Replies: 2
    Last Post: 04-04-2006, 11:36 PM