operator-keyword

c++: overloading + operator for a sparse matrix

void add(sparseMatrix<T> &b, sparseMatrix<T> &c); // c is output sparseMatrix<T> operator+(sparseMatrix<T> &b); I'm creating a sparse matrix which is made up of an arrayList of singly linked lists of matrix terms (matrix terms contain the row, column, and value). I'm having trouble overloading the + operator. I have an add method whic...

How should binary operators be defined in bison?

I'm writing a parser in C with bison, and while it appears to work correctly in all circumstances I've tried so far, I get a bunch of shift/reduce warnings on my binary operators (and one on my unary NOT operator as well). binary_op : PLUS { } | MINUS { } | TIMES { } | SLASH { } | POWER { } | AND { } ...

Trouble with inheritance of operator= in C++

I'm having trouble with the inheritance of operator=. Why doesn't this code work, and what is the best way to fix it? #include <iostream> class A { public: A & operator=(const A & a) { x = a.x; return *this; } bool operator==(const A & a) { return x == a.x; } virtual int get() = 0; ...

How to define cast operator in super class in C# 3.5?

Hi, I have a container class for adding some properties to standard data types like int, string and so on. This container class encapsulate an object of such an (standard type) object. Other classes then use sub classes of the container class for getting/setting the added properties. Now I want that the sub classes can implicitly cast b...

Operator overloading and namespaces

Possible Duplicate: Where should non-member operator overloads be placed? While browsing on SO, I often find questions or answer that involves overloading/defining a std::ostream& operator<<(std::ostream& os, const Foo& foo) or a Foo operator+(const Foo& l, const Foo& r). While I know how and when (not) to write these operato...

Python "++" operator doesn't work

Possible Duplicate: Python: Behaviour of increment and decrement operators Hi, I've tried this. ++num and the num doesn't change at all, always show the value when initialized if I change ++num to num+=1 then it works. So, my question is how that ++ operator works? ...

ANTLR: problem differntiating unary and binary operators (e.g. minus sign)

Hi guys, i'm using ANTLR (3.2) to parse some rather simple grammar. Unfortunately, I came across a little problem. Take the follwoing rule: exp : NUM | '(' expression OPERATOR expression ')' -> expression+ | '(' (MINUS | '!') expression ')' -> expression ; OPERATOR contains the same minus sign ('-') as is defined with MINUS. Now ...

Overloading + operator on generic class in C++

Hi all. I'm trying to overload the + operator in a forest class, a forest being a collection of trees, and the + operator is supposed to combine two forests into one. I have the following code as my class definition: template<typename NODETYPE> class Forest { public: friend Forest& operator+<>(Forest&, Forest&); ...

C# Implicit casting to List<T> returns runtime error

I have a class similar to the following that uses an internal List: public class MyList<T> : IEnumerable<T> { private List<T> _lstInternal; public MyList() { _lstInternal = new List<T>(); } public static implicit operator List<T>(MyList<T> toCast) { return toCast._l...

Calling primitive operator-functions explicitly in C++

int a, b, c; //do stuff. For e.g., cin >> b >> c; c = a + b; //works c = operator+(a,b); //fails to compile, 'operator+' not defined. This on the other hand works - class Foo { int x; public: Foo(int x):x(x) {} Foo friend operator+(const Foo& f, const Foo& g) { return Foo(f.x + g.x); } }; Foo l(5), m(1...