operators

Doubt regarding operators in C/C++/Java

Consider the follwoing fragment: int a,b; a = 1; b = 2; c = a++++b; // does not work!! Compilation error. c = a++*+b; // works !! Please help me understand this behaviour. ...

STL: how to overload operator= for <vector> ?

There's simple example: #include <vector> int main() { vector<int> veci; vector<double> vecd; for(int i = 0;i<10;++i){ veci.push_back(i); vecd.push_back(i); } vecd = veci; // <- THE PROBLEM } The thing I need to know is how to overload operator = so that I could make assignment like this: vector<double> = vector<int>; I'...

Override all operators in python

I have a wrapper class for an object. I want it to apply all operations applied to it on the wrapped object, e.g wrapper+=a would yield the same result as wrapped+=a, for instance. I want to apply this for all operators. Any simple way to override all operators without overriding each one explicitly? ...

When is Perl's scalar comma operator useful?

Is there any reason to use a scalar comma operator anywhere other than in a for loop? ...

Returning reference to class with overloaded private & operator?

I got a class called Property (from external library == cannot be modified) that has private overloaded & operator. I use this class in another class as a property and (for sanity reasons) I'd like to return a reference to this property through the Get method. However I got the 'cannot access private member declared in class' error I can...

Python != operation vs "is not"

In a comment on this question, I saw a statement that recommended using result is not None vs result != None I was wondering what the difference is, and why one might be recommended over the other? Thanks! ...

How to use C++ operators within python using boost::python (pyopencv)

I'm using the pyopencv bindings. This python lib uses boost::python to connect to OopenCV. Now I'm trying to use the SURF class but don't know how to handle the class operator in my python code. The C++ class is defined as: void SURF::operator()(const Mat& img, const Mat& mask, vector<KeyPoint>& keypoints) const {...}...

Can you define your own operators in F#?

Is there a way to define your own operators in F#? If so can someone give me an example for this? I searched briefly, but couldn't find anything. ...

Override 'in' operator in Python

If I am creating my own class in Python, what function should I define so as to allow the use of the 'in' operator, e.g. class MyClass(object): ... m = MyClass() if 54 in m: ... ...

c++ operator[] overloading problem (works fine but not for pointers, why?)

Problem with operator[] in c++, i have some class: 197 class Permutation{ 198 private: 199 unsigned int* array; 200 unsigned int size; 201 202 void fill(){ 203 for(unsigned int i=0;i<size;i++) 204 array[i]=i; 205 ...

What is the difference between the | and || operators?

| and || - what is the difference between these two operators in PHP? ...

Overloading the global type conversion operator

To test and display the result of some functions of my library, I am creating a set of handy functions. I have an execute function that looks like : template <typename R, typename I> std::string execute( const std::string& func_name, R(*func_ptr)( const I& ), const I& func_input ); It calls the function, and display the results and a...

how do I write a logger class with cout style interface (logger << "Error: " << val << endl;)

I want to create a logger class such that with a functionality like this: Logger log; log << "Error: " << value << "seen" << endl; This should print me a custom formatted message. E.g. "12-09-2009 11:22:33 Error 5 seen" My simple class currently looks like this: class Logger { private: ostringstream oss; public: ...

Ruby - newlines and operators

Consider the following code: x = 4 y = 5 z = (y + x) puts z As you'd expect, the output is 9. If you introduce a newline: x = 4 y = 5 z = y + x puts z Then it outputs 5. This makes sense, because it's interpreted as two separate statements (z = y and +x). However, I don't understand how it works when you have a newline within pa...

Why do I have to use a * in front of a Perl bareword filehandle?

While trying to do this: my $obj = new JavaScript::Minifier; $obj->minify(*STDIN, *STDOUT); // modified above line to $obj->minify(*IP_HANDLE,*OP_HANDLE) The above works if IP_HANDLE and OP_HANDLE are filehandles but still I am not able to figure out what actually the * does when applied to a filehandle or any other datatype. Than...

trying to make a simple grid-class, non-lvalue in assignment

I'm implementing a simple C++ grid class. One Function it should support is accessed through round brackets, so that I can access the elements by writing mygrid(0,0). I overloaded the () operator and i am getting the error message: "non-lvalue in assignment". what I want to be able to do: //main cGrid<cA*> grid(5, 5); grid(0,0) = new...

Are there any tools that can "find references" to built in ops?

I was reading the explanation under this item in the Google C++ style guide and it got me thinking; are there any tools that work like VS's "Find all references" tool but for built in ops and the like? For example say I want to find all places where the native "+" operator is used on a pointer (or maybe just a pointer to an object) and a...

Merging Dictionaries in Python

I am intrigued by the following python expression: d3 = dict(d1, **d2) The task is to merge 2 dictionaries into a third one, and the above expression accomplishes the task just fine. I am interested in the ** operator and what exactly is it doing to the expression. I thought that ** was the power operator and haven't seen it used in t...

overloading augmented arithmetic assignments in python

Hi all. I'm new to Python so apologies in advance if this is a stupid question. For an assignment I need to overload augmented arithmetic assignments(+=, -=, /=, =, *=, %=) for a class myInt. I checked the Python documentation and this is what I came up with: def __iadd__(self, other): if isinstance(other, myInt): self.a +...

Why does Javasript's strict comparison act the way it does?

Possible Duplicate: Is JavaScripts math broken? If the main difference between Javascript's "strict comparison" operators and the traditional ones is type coercion, why does 0.1+0.2===0.3; return false? Riddle me this, Batman. ...