uh... -> .* * ! | & ^= ++ @(#)$*&#@!!!

This is a discussion on uh... -> .* * ! | & ^= ++ @(#)$*&#@!!! within the C++ Programming forums, part of the General Programming Boards category; Operators... I'm confused. In my C++ book -> is listed at the same operational level as .* and * . ...

  1. #1
    Authorized Technician
    Join Date
    Jul 2004
    Posts
    11

    uh... -> .* * ! | & ^= ++ @(#)$*&#@!!!

    Operators... I'm confused.

    In my C++ book -> is listed at the same operational level as .* and *. I know *, that's with pointers. But what is this -> operator? While we're on the subject, what's all these mean?

    ^=
    .*
    >>
    << (I know how to use it, but what is it really?)
    <<=
    >>= (who thinks of these?)
    ?: This is the trinary operator, is it not?

    Any more weird ones to add?
    Anyways, I think it would be a good idea for all the CPP operators to be put in one thread and put somewhere convienient.

    <edit>
    How 'bout:
    ~
    all these 'boolean' operators
    ^
    &
    |
    My list (C++ book) says:
    Sizeof
    new
    delete
    but I don't quite get how those are operators
    </edit>
    Last edited by Bomber_nuke88; 08-06-2004 at 08:00 PM.
    Behind me lies another fallen soldier...

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Code:
    ^=     Think of this as += but a bitwise XOR instead of plus
    .*       Acces to member *
    >>     Right shift (bit shifting) overloaded with cin/cout to be input/ouput
    <<     Left I am sillyI am sillyI am sillyI am silly (see above)
    <<=   Again, just like += but with left I am sillyI am sillyI am sillyI am silly instead of plus
    >>=   Same as above, but with right shift
    ?:       This is a conditional statement... (see below)
    var = Statement ? varEqualsThisValueIffStatementIsTrue : elseThisValue;
    ex) int x = ( y < 4 ) ? 4 : x-1;
    Last edited by Perspective; 08-06-2004 at 08:19 PM.

  3. #3
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    ~ Ones compliment
    ^ Bitwise XOR
    & Bitwise AND
    | Bitwise OR

    >> My list (C++ book) says:
    sizeof
    new
    delete
    >> but I don't quite get how those are operators

    these are operators just the same as the others, they just use keywords instead of symbols. i assume you dont need explanations of these?

  4. #4
    C++ n00bie :D
    Join Date
    Jul 2004
    Posts
    63
    so there is a XOR operator in C++
    :Points to member title:
    What can I say...

  5. #5
    Authorized Technician
    Join Date
    Jul 2004
    Posts
    11
    Nah, I'm solid on my memory deal, mostly... Those crazy ones (<<=) are what I'm curious about. I think I saw -> in a windows code example (my next venture in CPP: windows).
    Behind me lies another fallen soldier...

  6. #6
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Ha ha - I think someone's missing the f in shift when they're typing (*cough* perspective *cough*). << and >> are also used as "extraction" and "insertion" operators in cin and cout. They're overloaded - if you don't know what that means - just remember it for when you do.

  7. #7
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Just so I can be useful... let me explain bit shifting...

    10 >> 1 = 5

    omg how can that be!?

    10 in binary is 1010
    5 in binary is 0101

    so if you have 1010 and shift all the bists to the right once 0101.... ooo its 5

    and of course << is shifting to the left.

  8. #8
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Basic rule:

    x >> n = x / (2^n)
    x << n = x * (2^n)
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by XSquared
    Basic rule:

    x >> n = x / (2^n)
    x << n = x * (2^n)
    We'll assume you mean "2 to the nth power", and not "2 XOR n".

    Quzah.
    Hope is the first step on the road to disappointment.

  10. #10
    Authorized Technician
    Join Date
    Jul 2004
    Posts
    11
    Let's get this strait, for the record then:

    << >>
    Instertion/extraction, bitshift.
    + - * / &
    add, subtract, multiply, divide, modulus
    < <= > >= == !=
    less than, lessthan or equal, greater than, greater than or equal, comparative-equal, not equal
    =
    define equal
    && ||
    same as AND and OR
    ++ --
    postfix/prefix increment/decrement
    & | ^
    bitwise AND, OR, XOR... works like an operation but by bits
    *= /= += -= %=
    op-equal, it does the operation and assigns the variable
    &= ^= |=
    does the bitwise operation and assigns the variable
    ?:
    (expression)?if_true:if_false


    what's left (I think)
    .*
    ->
    <<=
    >>=
    ~

    I do believe that is every builtin operator for C++.
    Last edited by Bomber_nuke88; 08-07-2004 at 05:38 AM.
    Behind me lies another fallen soldier...

  11. #11
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    .* Someone said something about accessing member * of a class, but I have never seen this.

    -> When referring to a structure or object directly, you can use the . operator. (objectname.membername). If you have a pointer to that object, you use the -> operator and don't need to dereference (pointername->membername - then you just treat it like you're using it directly without a pointer)

    <<= >>= Performs a bit shift and assings the variable

    ~ One's complement, or the NOT operator. Someone already told you this.

    Also, make sure you understand the difference between the logical AND and the bit-wise AND (not to mention the other operators), but it sounds like you may already know.

  12. #12
    Authorized Technician
    Join Date
    Jul 2004
    Posts
    11

    many a thanks

    thanks, you guys rock. That's about all anybody could ask for operators.
    Behind me lies another fallen soldier...

  13. #13
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    ->* and .* are the membership dereference operators, and adding to what sean said, they allow you to point to member variables in a different way. They are useful when you deal with arrays of pointers to member functions that aren't static (ie: have the this pointer) and you can do some other neat stuff.
    Code:
    class Func
    {
    public:
       int code;
       void foo(int i);
    };
    
    int main(void)
    {
        int Func::*pm = &Func::code;   // this is legal, believe it or not
        void (Func::*pf)(int) = &Func::foo;   //this is legal too!
        Func f1;
        Func  * f2 = new Func;
    
        f1.*pm = 1;
        f2->*pm = 2;
        
        (f1.*pf)(3);
        (f2->*pf)(4);
        .....
    }
    Last edited by skorman00; 08-07-2004 at 09:11 AM.

  14. #14
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by Me
    >> Right shift (bit shifting) overloaded with cin/cout to be input/ouput
    << Left I am sillyI am sillyI am sillyI am silly (see above)
    hehehe, yeah. that was supposed to be Left shift.

  15. #15
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Quote Originally Posted by quzah
    We'll assume you mean "2 to the nth power", and not "2 XOR n".

    Quzah.
    Yeah, 2^n in that case is pow( 2, n ), not 2 xor n. Whoops
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Page 1 of 2 12 LastLast
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. Changing flags from a DLL?
    By RobotGymnast in forum C++ Programming
    Replies: 17
    Last Post: 10-27-2008, 01:34 PM
  3. Dev-C++ -> Tools - > Editor -> Syntax
    By Yuri2 in forum C++ Programming
    Replies: 19
    Last Post: 07-03-2006, 07:48 AM
  4. > > > Urgent Help < < <
    By CodeCypher in forum C Programming
    Replies: 2
    Last Post: 01-31-2006, 01:06 PM

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