Funky operators?

This is a discussion on Funky operators? within the C++ Programming forums, part of the General Programming Boards category; Hi, I was wondering about two things: What does *& mean? I know it could be interpreted as "A pointer ...

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    1

    Funky operators?

    Hi, I was wondering about two things:

    What does *& mean? I know it could be interpreted as "A pointer to a reference," but when would one use such an operator? For example:
    Code:
    ClassV1 *Info; // .. initialize it elsewhere
    ...
    ClassV2*& Info2 = (ClassV2*&)Info;
    I don't understand exactly what they're doing and why. (Note that ClassV2 inherits from ClassV1)

    The second operator I've seen is !!

    For instance:

    return !!(some expression); // this is inside a function

    It seems to me that it just makes sure that the expression returns a bool? Is this used when you have an expression returning an int but you want to force it to return a bool? That's my guess. Anyways, thanks in advance, any input would be appreciated.

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    161
    *& is actually a reference to a pointer. It's useful when you want to change a pointer that you've passed to a function.

    !! will do just as you said, but it's not particularly useful in C++ because most values that can be represented as bools will be automatically cast to the correct type.
    Last edited by thefroggy; 11-10-2003 at 02:05 AM.

  3. #3
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571

    Re: Funky operators?

    Originally posted by M0onshine
    Hi, I was wondering about two things:

    What does *& mean? I know it could be interpreted as "A pointer to a reference," but when would one use such an operator? For example:
    Code:
    ClassV1 *Info; // .. initialize it elsewhere
    ...
    ClassV2*& Info2 = (ClassV2*&)Info;
    I don't understand exactly what they're doing and why. (Note that ClassV2 inherits from ClassV1)

    The second operator I've seen is !!

    For instance:

    return !!(some expression); // this is inside a function

    It seems to me that it just makes sure that the expression returns a bool? Is this used when you have an expression returning an int but you want to force it to return a bool? That's my guess. Anyways, thanks in advance, any input would be appreciated.
    The first one is a reference to a pointer. Say you want to modify a pointer itself (make it point somewhere else, not just modify the data it points at). You need to pass it by reference or by pointer, so you need to use a reference to a pointer, or a pointer to a pointer.

    For the second, if the function's return type was bool, it would not need the !!. This is typically used when you want to return an int that represents true or false. In such a case, when x == 0, !!x == 0, and when x != 0, !!x = 1. It's a way of forcing the value to be 0 or 1 (so you couldn't return 2, for example).
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical Operators in C++
    By Flecto in forum C++ Programming
    Replies: 4
    Last Post: 05-15-2009, 08:17 AM
  2. Bolean Operators hurt my head. (Trouble understanding) :(
    By Funcoot in forum C++ Programming
    Replies: 3
    Last Post: 01-20-2008, 07:42 PM
  3. operators???
    By arjunajay in forum C++ Programming
    Replies: 11
    Last Post: 06-25-2005, 05:37 AM
  4. Boolean Operators?
    By civilwarsearch in forum C++ Programming
    Replies: 11
    Last Post: 12-15-2003, 09:50 PM
  5. Operators
    By George in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2003, 07:35 PM

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