operator-keyword

how to define following operator/function in python ?

i am new to programming need to define operator/function s^m such that s^m(a^g^n+b^g^o+c^g^p*d^g^q)+a^g^f=a^g^(n+m)+b^g^(o+m)+c^g^(p+m)*d^g^(q+m)+a^g^f a b c d g ..all symbols ^=power ,in simple language operator which will transform all 'g's in bracket to g^m while keeping those out of bracket as it is . i am working on solving ...

c++: set<customClasS* how to overload operator<(const customClass&*...)?!

Good Evening (depending on where u are right now). I am a little confused with the stl stuff for sorted sets... I want to store pointers of a custom class in my set and I want them to be sorted by my own criterion and not just the pointer size. Anyone has an idea how to do this? Since it is impossible to do it like operator<(const foo ...

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...

Operator commutativity for inequality != in C++

Hi, I have a quick question about the following expression: int a_variable = 0; if(0!=a_variable) a_variable=1; what is the difference between "(0 != a_variable)" and "(a_variable != 0)" ? I dont have any errors for now but is this a wrong way to use it?? ...

Are there any other keywords that can be accessed using the global namespace scope resolution operator?

The global new and delete can be used like normal, but you can also prefix the :: operator to them and it will work the same. Are there any other keywords that have this same behaviour? Thanks. ...

C extension: <? and >? operators

I observed that there was at some point a <? and >? operator in GCC. How can I use these under GCC 4.5? Have they been removed, and if so, when? Offset block_count = (cpfs->geo.block_size - block_offset) <? count; cpfs.c:473: error: expected expression before ‘?’ token ...

How to define an operator alias in PostgreSQL?

Is there an easy way to define an operator alias for the = operator in PostgreSQL? How is that solved for the != and <> operator? Only the <> operator seems to be in pg_operators. Is the != operator hard-coded? This is needed for an application which uses a self-defined operator. In most environments this operator should act like a =, ...

[C++] operator << - how to detect last argument.

hi guys, I'm writting a log class in c++. This class is an singleton. I want to add logs in such a way: Log::GetInstance() << "Error: " << err_code << ", in class foo"; Ok, and inside a Log object, I want to save this whole line at the time when the last argument comes (", in class foo" in this example). How to detect the last one <...

C++ overloading conversion operator for custom type to std::string

Hi, I hope someone might be able to answer why the following doesn't work. Bear with me though, I am still very much a noob... I just cannot get to the bottom of why the following using namespace std; #include <string> #include <iostream> class testClass { public: operator char* () {return (char*)"hi";}; operator int () {return 77;}...

Why do I need the `new` keyword for an instance of `Date` in JavaScript?

I understand the difference in behavior. Date() returns a String representing the current date, and new Date() returns an instance of the Date object whose methods I can call. But I don't know why. JavaScript is prototyped, so Date is a function and an object which has member functions (methods) which are also objects. But I haven't wri...

Operator << overload in c++

#include <iostream> #include <fstream> class obj { public: int i; friend ostream& operator<<(ostream& stream, obj o); } void main() { obj o; ofstream fout("data.txt"); fout<<o; fout.close(); } This is the my code, am getting error. error : ostream : ambiguous symbol. any one can help me. ...

operator overloading

Hi, I've created a class myString and I'm trying to run the following code: class myString{ char* str; int len; public: myString(char* str1 = " "){ len = strlen(str1); str = new char[len+1]; strcpy(str, str1); }; int getLen() const { return len; }; char* getString() const {...

overloading dereference operator

hi, I am new to C++ and i have a question on overloading dereference operator. I am building a in memory object store which is to be used by the applications. The data store is mapped in to the applications memory space and applications can directly read/modify the object using dereference operator . I plan to provide an interface desc...

C#: Are string.Equals() and == operator really same?

Are they really same? Today, I ran into this problem. Here is the dump from the Immediate Window: ?s "Category" ?tvi.Header "Category" ?s == tvi.Header false ?s.Equals(tvi.Header) true ?s == tvi.Header.ToString() true So, both s and tvi.Header contain "Category", but == returns false and Equals returns true. s is defined as...

C++: pure virtual assignment operator

why if we have pure virtual assignment operator in a base class, then we implement that operator on the derived class, it give linker error on the base class? currently I only have the following explanation on http://support.microsoft.com/kb/130486 , it said that the behavior is by design since normal inheritance rules does not apply. ...

What do the * and & operators operate on if the argument is complex?

Simply, is &someObject->someAttribute.someMember; equivalent to &(someObject->someAttribute.someMember); or (&someObject)->someAttribute.someMember; or (&(someObject->someAttribute)).someMember; Or should you really put explicit parenthesis there just to be safe? ...

Question about == operator in java

public class Demo { public static void main(String[] args) { String s1 = "Hello"; String s2 = "Hello"; System.out.println("s1 == s2 " + (s1 == s2)); String s5 = "Hel" + "lo"; String s6 = "He" + "llo"; System.out.println("s5 == s6 " + (s5 == s6)); String s7 = "He"; ...

Determining available operators at runtime

I would like to be able to retrieve the available operators for an object at runtime, possibly in a similar way as the getMethod() call. In particular, I need to be able to call the less-than/greater-than operators of an object at runtime. Basically, I have a bunch of primitives that have been cast to the Object object-type. I need to...

C++: Custom data type - typecasting and union issues

What I'm trying to do is create a new custom data type that behaves like all other primitive types. Specifically, this data type appears like a Fixed Point fraction. I've created a class to represent this data type, called "class FixedPoint", and in it there are ways to typecast from "FixedPoint" to "int" or "double" or "unsigned int", ...

Use list cons operator (a :: b) as a function

F# lets you turn operators into functions by surrounding them with ( ): for instance, (+) is of type int -> int -> int. Is it possible to do this with the list cons operator, ::? It doesn't behave like a normal binary operator: FSI> (::);; (::);; -^^ c:\temp\stdin(3,2): error FS0010: Unexpected symbol '::' in expression. Expecte...