operator-overloading

How can I "double overload" an operator?

If I have a database-like class, and I want to do something like this: object[1] == otherObject; How do I "double overload" operator[] and operator==? ...

Undefined reference to external variable

Having problems with a custom logging system I've made. I am declaring an ofstream within my main file so that it is accessible by static functions within my class. This works for my static function (ilra_log_enabled). However, this does not work on my overloaded function for the class. I receive a undefined reference to "logfile" error....

Python : Operator Overloading a specific type

I'd like to be able to have the operator of my class interact with regular types in a way that I define. Lets say, for example, I have: class Mynum(object): def __init__(self, x): self.x = x def __add__(self, other): return self.x + other.x a = Mynum(1) b = Mynum(2) print a+b This works just fine, but now if I try to do: ...

Redirecting ostream to file not working

I have a custom logging system which allows me to send information to a log file and the console depending on the verbosity currently selected. Right now, the trouble I am having is with the output to the file, with output to the console working fine. Here is an example: ilra_talk << "Local IP: " << systemIP() << " | Hostname: "...

Error with C++ operator overloading, in Visual Studio AND Xcode

...

When is the const operator[] called and when is the non-const operator[] called?

I have two very different behaviors for reads and writes. In the event of reads, I want to copy a buffer of a rather hard to extract data structure. On writes, I will just write unbuffered to the structure. Up to now, I have been using operator[] to do access, so for the sake of polymorphism I'd like to continue doing so. So my quest...

Overloading operator++ prefix / postfix in terms of each other?

I have a question that may have been answered over 9000 times before but I really don't know how to word it, this is what I am going to try. I've seen in some C++ books and tutorials that when defining your own class which has a iterable value (incrementable) semantics, you can overload operator++ for it (all I'm going t state here I'd ...

Overloading operator<< to work for string

Hi! In the following code: using namespace std; //ostream& operator<< (ostream& out,const string & str) //{ // out << str.c_str(); // return out; //} int _tmain(int argc, _TCHAR* argv[]) { ofstream file("file.out"); vector<string> test(2); test[0] = "str1"; test[1] = "str2"; ostream_...

Java - Passing value to MyOwnClass throe "="

Can I pass a value to my own String-like class like this: MyClass mc = "String"; Is it even possible? ...

Operator Overloading Javascript? (def.js)

Possible Duplicate: Javascript syntax I havent seen till now, what does it do really? Just saw http://github.com/tobeytailor/def.js today, and I don't understand how this works: def ("Ninja") << Person ({ init: function(name){ this._super(); }, kick: function(){ this.speak("I kick u!"); } }); ...

Cascading for overloaded + operator

Here's the current code: const complex complex::operator+(const complex &right) { complex result; result.realPart = realPart + right.realPart; result.imPart = imPart + right.imPart; return result; } How do i modify so that a = b + c + d; is allowed? ...

Expression intermediates in GCC (if that's what they're actually called)

I am trying to convert a math library written with VS so it will compile though GCC. The trouble is, I have a lot of overloaded operators that look like this: template<typename T> inline quaternion<T> operator+(quaternion<T> &a, quaternion<T> &b) {return quaternion<T>(a.x+b.x,a.y+b.y,a.z+b.z,a.w+b.w);} and so on. The problem is: Thes...

istream_iterator leaking memory

All right, you guys were very helpful with my last question, so I'll try another one. This is also homework and while the last one was quite old, this has been submitted and is waiting to be marked. So if there's anything that will bite me it'll probably be this problem. I've obfuscated the class names and such since it's still possible ...

C++ noob question: pointers and overloaded []

I've been staring at this for a while and not getting very far. FruitBasketFactory, FruitBasket, and Fruit are three classes from an API I'm using. My goal is to make a fruit basket and then retrieve the fruit. According to the FruitBasketFactory.hpp: const FruitBasket* getFruitBasket() const; and then in the FruitBasket.hpp siz...

How to implement pre and post-increment / decrement operator in my class?

I want to overload ++ operator to use pre-increment and post-increment using operator overloading in my c# class. But only post-increment is working. How to make both function works in my class? Suppose I made a class ABC like - using System; using System.Collections.Generic; using System.Text; namespace Test { class ABC { ...

can I specialize operator<< ?

Hi, I want to specialize operator<< but this code is not compiling; template<> std::ostream& operator<< < my_type >( std::ostream& strm, my_type obj); ...

Help understanding class example code for C++, templates, operator()

I'm not sure exactly what the following class does that we have for a class example. In the following code, what does the operator() do in this case? I don't quite get the *(begin + first) and pretty much the whole return expression as what is being evaluated. Any help would be great. Thanks! // IndexCompare.h - interface for IndexC...

C++ Classes and Overloaded Operators

I have been trying to make a StringTable class that holds a simple unordered_map<string, string>, and has the array index operator '[]' overloaded to work for accessing the map; however, the compiler will tell me that I have yet to define the overloaded operator when I try to use it. My code is as follows: CStringTable.h #include <stri...

c++ friend function - operator overloading istream >>

Hello all, My question is in regards to friend functions as well as overloading the << and >>. From my understanding I thought friend functions could (and should) access private member variables directly. However in the case I have here the compiler would only accept my .cxx file when I used "get" functions to obtain each private variab...

Overload operator == for STL container

I'm trying to remove a class object from list<boost::any> l l.remove(class_type); I tried writing something like this as a member function bool operator == (const class_type &a) const //not sure about the arguments { //return bool value } How would you write an overload function to remove an object of class from a std::list of b...