operators

C++ template class error with operator ==

Error: error C2678: binary '==' : no operator found which takes a left-hand operand of type 'const entry' (or there is no acceptable conversion) The function: template <class T, int maxSize> int indexList<T, maxSize>::search(const T& target) const { for (int i = 0; i < maxSize; i++) if (elements[i] == target) //ERROR??? ...

Creating a "logical exclusive or" operator in Java

Observations: Java has a logical AND operator. Java has a logical OR operator. Java has a logical NOT operator. Problem: Java has no logical XOR operator, according to sun. I would like to define one. Method Definition: As a method it is simply defined as follows: public static boolean logicalXOR(boolean x, boolean y) { retu...

Operator = Overload with Const Variable in C++

Hi everybody. I was wondering if you guys could help me. Here are my .h: Class Doctor { const string name; public: Doctor(); Doctor(string name); Doctor & Doctor::operator=(const Doctor &doc); } and my main: int main(){ Doctor d1 = Doctor("peter"); Doctor d2 = Doctor(); d2 = d1; } I want to ...

Bind pointer to member operators in C++

What is the point of them? I've never used them for anything, and I can't see myself needing to use them at all. Am I missing something about them or are they pretty much useless? EDIT: I don't know much about them, so a description about them might be necessary... ...

The ternary (conditional) operator in C

What is the need for the conditional operator? Functionally it is redundant, since it implements an if-else construct. If the conditional operator is more efficient than the equivalent if-else assignment, why can't if-else be interpreted more efficiently by the compiler? ...

Understanding evaluation of expressions containing '++' and '->' operators in C.

Consider this example: struct { int num; } s, *ps; s.num = 0; ps = &s; ++ps->num; printf("%d", s.num); /* Prints 1 */ It prints 1. So I understand that it is because according to operators precedence, -> is higher than ++, so the value ps->num (which is 0) is firstly fetched and then the ++ operator operates on it, so it incre...

Overloading +/- unary operators

When you overload the - unary operators, for an immutable type, you can write it like: public static Point3 operator - (Point3 p) { return new Point3 (-p.X, -p.Y, -p.Z); } But for the + unary operator, how should you implement it? Like this: public static Point3 operator + (Point3 p) { return p; } or like this: public stat...

What is the !! operator in JavaScript?

I've seen code that seems to use an operator I don't recognize, in the form of two exclamation points, like so: !!. Can someone please tell me what this operator does? ...

How does the bitwise complement (~) operator work?

Why is it that ~2 is -3? ...

What does '?' do in C++?

int qempty(){ return(f==r)?1:0;} In the above snippet, what does "?" mean? What can we replace it with? ...

Haskell Cons Operator (:)

I am really new to Haskell (Actually I saw "Real World Haskell" from O'Reilly and thought "hmm, I think I'll learn functional programming" yesterday) and I am wondering: I can use the construct operator to add an item to the beginning of a list: 1 : [2,3] [1,2,3] I tried making an example data type I found in the book and then playing...

C# what does the == operator do in detail?

in c# what does exactly happen in the background when you do a comparison with the "==" operator on two objects? does it just compare the addresses? or does it something like Equals() or CompareTo() ? PS: what about the "==" operator in java? does it behave the same? ...

x=x+1 vs. x +=1

I'm under the impression that these two commands result in the same end, namely incrementing X by 1 but that the latter is probably more efficient. If this is not correct, please explain the diff. If it is correct, why should the latter be more efficient? Shouldn't they both compile to the same IL? Thanks. ...

OR Operator in c#

Can I achieve if(a == "b" || "c") instead of if(a == "b" || a== "c") ...

What is the "??" operator for?

I was wondering about "??" signs in c# code.. what is it for? And how can i use it? what about "int?"? is it nullable int? See also: ?? Null Coalescing Operator —> What does coalescing mean? ...

Ruby spaceship operator <=>

What is the Ruby spaceship operator? Is the operator implemented by any other languages? ...

What does the || operator do?

Attacklab.wmd_env.buttons=Attacklab.wmd_env.buttons||_4; what does the || do in this case? Adds _4 to the array which is Attacklab.wmd_env.buttons? ...

Why is there no ^^ operator in C/C++?

& has &&. | has ||. Why doesn't ^ have ^^? I understand that it wouldn't be short-circuiting, but it would have different semantics. In C, true is really any non-zero value. Bitwise XOR is not always the same thing as logical XOR: int a=strcmp(str1,str2);// evaluates to 1, which is "true" int b=strcmp(str1,str3);// evaluates to 2, whic...

Semantics of ">>" operator in F#

In Microsoft's F# samples, they use the ">>" operator as follows: test |> Seq.iter (any_to_string >> printfn "line %s"); What does the ">>" operator do in this context? Is each item of the sequence (an array in this case) get passed to any_to_string implicitly? Is this similar to (fun item -> printfn "line %A" item)? ...

What does === do in PHP.

I have been programming in PHP for a while but I still dont understand the difference between == and ===. I know that = is assignment. And == is equals to. So what is the purpose of ===? ...