Results 1 to 5 of 5

Thread: what is difference between . and ->

  1. #1

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    what is difference between . and ->

    I saw some code here and somebody decaled a type like:

    POINT pt;

    Now here accessed the "x" value in the variable pt like this:

    switch(pt -> x)

    Can I write the samething as:

    switch(pt.x)

    Is there any difference when you use "->" and "." ?
    Baaaaaaaaah

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    There's a big difference. See the other threads about -> because I don't want to type it out again
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    denniswrenn
    Guest

    Re: what is difference between . and ->

    Originally posted by abdul
    I saw some code here and somebody decaled a type like:

    POINT pt;

    Now here accessed the "x" value in the variable pt like this:

    switch(pt -> x)

    Can I write the samething as:

    switch(pt.x)

    Is there any difference when you use "->" and "." ?
    when you have a pointer, you use -> to access it's members, if it's just a regular variable you use .

    Code:
    struct test{
    int x;
    };
    
    test tVar;
    test* tpVar;
    
    tVar.x = 5; //yes
    
    tpVar.x = 5; //no
    tpVar->x = 5; //yes
    (*tpVar).x = 5 // yes

  4. #4

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    Can you expalain more

    I have read about pointers but just forgot a bit so
    Can you explain the examples which you gave me (a kind of another approach) because i did not understand the "struct" and then a bracket and then "You have declared a variable"
    Can you explaim me please that what is happening in that example


    That would be really helpfull
    Baaaaaaaaah

  5. #5
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    In fact, an expression involving the member-selection operator (->) is a shorthand version of an expression using the period (.) if the expression before the period consists of the indirection operator (*) applied to a pointer value. Therefore,

    expression -> identifier

    is equivalent to

    (*expression) . identifier

    when expression is a pointer value.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width