What does -> mean.....

This is a discussion on What does -> mean..... within the Windows Programming forums, part of the Platform Specific Boards category; Not sure if this is the right board, but........ Recently brought "Practical Visual C++ 6", and it uses a lot ...

  1. #1
    www.entropysink.com
    Join Date
    Feb 2002
    Posts
    605

    What does -> mean.....

    Not sure if this is the right board, but........

    Recently brought "Practical Visual C++ 6", and it uses a lot of syntax like

    Code:
    GetDlgItem(IDC_CENTER) ->ShowWindow(bVisible ? SW_HIDE : SW_SHOW)
    While I can see this is extremely efficient "function crunching", it is also "newbie unfriendly"!

    So just to ensure I have got this straight, am I right in saying this is equivalent to...

    Code:
    button1=GetDlgItem(IDC_LEFT);
    bVisible = bVisible ? SW_HIDE : SW_SHOW;
    button1.ShowWindow(bVisible);
    (I know the syntax may be wrong here, but it is the sense of the syntax I am trying to capture!!)

    Also, am I right in saying that -> is read as "is a member function of"??

    Thanks,

    Rob.
    Visit entropysink.com - It's what your PC is made for!

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    88
    hmmmm

    i dont sure

    i wanted to ask it to
    but i think it is like :

    GetDlgItem(IDC_CENTER) . ShowWindow(bVisible ? SW_HIDE : SW_SHOW)


    dont sure

    but it do the same
    if i right

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Code:
    GetDlgItem(IDC_CENTER) ->ShowWindow(bVisible ? SW_HIDE : SW_SHOW)
    GetDlgItem() returns a pointer to a CWnd (Window wrapper).....

    So with this call you have a pointer to an item from a dialog that is derived from a CWnd.....now the '->' is the same as the '.' operator that allows you access to member functions of an object that you have made an instance of.....but the '->' is used when you have a pointer to an object......so in essence you are now calling the ShowWindow() member function of CWnd.....

    The "bVisible ? SW_HIDE : SW_SHOW" represents a ternary logic operator (ternary refering to the fact that it has 3 operators!)...

    It means "if bVisible is true, this will be SW_HIDE....failing that it will be SW_SHOW"....

    It can be rewritten as

    Code:
    bool bVisible;
    
    //........whatever makes bVisible true or false
    
    CWnd* MyWnd = NULL;
    int nCommandShow;
    
    MyWnd = GetDlgItem(IDC_CENTER);
    
    if( bVisible == true ){
    nCommandShow = SW_HIDE;
    }
    else{
    nCommandShow = SW_SHOW;
    }
    MyWnd->ShowWindow(nCommandShow);

  4. #4
    www.entropysink.com
    Join Date
    Feb 2002
    Posts
    605
    Cheers Rob,

    I see (I think)!

    One last thing, your example re-write used

    MyWnd->ShowWindow(nCommandShow);

    The real question was, is there any way to rewrite the original without using -> (as it was the -> that was confusing me).

    Mind you, just asking the question helped me understand it!
    Visit entropysink.com - It's what your PC is made for!

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by RobR

    One last thing, your example re-write used

    MyWnd->ShowWindow(nCommandShow);

    The real question was, is there any way to rewrite the original without using -> (as it was the -> that was confusing me).
    Yes...but get used to the -> operator as you will see alot of it......

    To stop using it you can derefrence the object you are calling on

    Code:
    *MyWnd.ShowWindow(nCommandShow);

  6. #6
    www.entropysink.com
    Join Date
    Feb 2002
    Posts
    605
    Yes...but get used to the -> operator as you will see alot of it......

    To stop using it you can derefrence the object you are calling on


    Code:
    *MyWnd.ShowWindow(nCommandShow);

    Excellent. Many thanks.

    Understand your comment about getting used to it. It's just that I like to understand things in comparison to what I already know (if you see what I mean).
    Visit entropysink.com - It's what your PC is made for!

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    77
    Originally posted by Fordy
    Code:
    GetDlgItem(IDC_CENTER) ->ShowWindow(bVisible ? SW_HIDE : SW_SHOW)
    GetDlgItem() returns a pointer to a CWnd (Window wrapper).....

    So with this call you have a pointer to an item from a dialog that is derived from a CWnd.....now the '->' is the same as the '.' operator that allows you access to member functions of an object that you have made an instance of.....but the '->' is used when you have a pointer to an object......so in essence you are now calling the ShowWindow() member function of CWnd.....

    The "bVisible ? SW_HIDE : SW_SHOW" represents a ternary logic operator (ternary refering to the fact that it has 3 operators!)...

    It means "if bVisible is true, this will be SW_HIDE....failing that it will be SW_SHOW"....

    It can be rewritten as

    Code:
    bool bVisible;
    
    //........whatever makes bVisible true or false
    
    CWnd* MyWnd = NULL;
    int nCommandShow;
    
    MyWnd = GetDlgItem(IDC_CENTER);
    
    if( bVisible == true ){
    nCommandShow = SW_HIDE;
    }
    else{
    nCommandShow = SW_SHOW;
    }
    MyWnd->ShowWindow(nCommandShow);

    bool bVisible
    is it the same as the bolean in java programing ????
    it only return true or false??

  8. #8
    www.entropysink.com
    Join Date
    Feb 2002
    Posts
    605
    Correct. Taken from boolean mathematics (George Boole, 17th century engineer i believe - may have got the century wrong, but you get the point).
    Visit entropysink.com - It's what your PC is made for!

  9. #9
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by monkeymon



    bool bVisible
    is it the same as the bolean in java programing ????
    it only return true or false??
    Yeah.......C++ allows the use of a boolean primitive variable......it can be true or false.....If I wanted to, I could have also used the WinAPI typedef BOOL

  10. #10
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    GetDlgItem(IDC_CENTER) ->ShowWindow(bVisible ? SW_HIDE : SW_SHOW)

    can be rewritten as

    ShowWindow( GetDlgItem(IDC_CENTER), bVisible ? SW_HIDE : SW_SHOW);

    or even

    ShowWindow( GetDlgItem(IDC_CENTER), bVisible);

    as SW_HIDE is defined as =0 (SW_SHOW=5)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  11. #11
    Assembler + Basic from 79
    Join Date
    Apr 2002
    Location
    Canada
    Posts
    22
    RobR,
    I re-ran into the same confusion recently myself...

    Fordy,
    You explained that very well. You'd better be careful, Someones gonna start using terms like "Knowledgeable" when refering to you

    Code:
    Fordy Robr();
    
    val = Robr->SetTitle("Knowledgeable");
    Remember Robr, your only an instance.
    Last edited by Guardian; 04-30-2002 at 10:17 AM.
    Twin engine aircraft are way better. If one engine quits the other takes you to the scene of the crash.

  12. #12
    Registered User DeadArchDown's Avatar
    Join Date
    Apr 2002
    Posts
    28
    I think you will have to use

    Code:
     (*MyWnd).ShowWindow(nCommandShow);
    because the . is processed first. Thats why they use the ->, all those paretheses and * get confusing fast.
    -------------------
    "Exception"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. small -> big -> bigger -> bigger than bigger -> ?
    By happyclown in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 03-11-2009, 12:12 PM
  2. Dev-C++ -> Tools - > Editor -> Syntax
    By Yuri2 in forum C++ Programming
    Replies: 19
    Last Post: 07-03-2006, 07:48 AM
  3. > > > Urgent Help < < <
    By CodeCypher in forum C Programming
    Replies: 2
    Last Post: 01-31-2006, 01:06 PM
  4. electricity > AC circuits > tesla coil
    By dbaryl in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 03-14-2002, 01:16 PM

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