operator-overloading

C++ : error: invalid operands of types ‘String*’ and ‘const char [7]’ to binary ‘operator+’

Hi, I'm learning cpp and In my last assignment I am rewriting the std::string class. so here is an outline of my code: string class: class String { public: String(const char* sInput) { string = const_cast<char*> (sInput); } const String operator+(const char* str) { //snip print(); ...

using class specific set_new_handler.

For class specific new_handler implementation, i came across the following example in book "effective c++". This looks problem in multithreaded environment, My Question is how to achieve class specific new_handler in multithreaded environment? void * X::operator new(size_t size) { new_handler globalHandler = // insta...

Why don't iostream objects overload operator bool?

In this answer I talk about using a std::ifstream object's conversion to bool to test whether the stream is still in a good state. I looked in the Josuttis book for more information (p. 600 if you're interested), and it turns out that the iostream objects actually overload operator void*. It returns a null pointer when the stream is ba...

What to do in class specific version of placement new ?

Class-specific version of placement new can be provided even though you can't replace the global one. What scenarios exist where a class should provide its own placement new operator? Even if my class don't implement placement new the following code works (assuming for abc no operator new is overloaded). char arr[100]; abc *pt = n...

Is it possible to override the array access operator for pointers to an object in C++?

I'm trying to do some refactoring of code, and have run into a problem. The program has a data manager that returns pointers to arrays of structures as a void*. One of the new types of data, instead of having a single pointer to an array of structures, has two pointers to arrays of numbers. The problem is that all the processing code ...

How do I overload an operator for an enumeration in C#?

I have an enumerated type that I would like to define the >, <, >=, and <= operators for. I know that these operators are implictly created on the basis of the enumerated type (as per the documentation) but I would like to explictly define these operators (for clarity, for control, to know how to do it, etc...) I was hoping I could do ...

Overloading operator [] for a sparse vector

I'm trying to create a "sparse" vector class in C++, like so: template<typename V, V Default> class SparseVector { ... } Internally, it will be represented by an std::map<int, V> (where V is the type of value stored). If an element is not present in the map, we will pretend that it is equal to the value Default from the template a...

C++ static operator overloading

Is it possible to overload C++ class operators in the static context? e.g. class Class_1{ ... } int main() { Class_1[val]... } ...

How to overload operators with Boost.Python

I am trying to overload operators of a C++ class using Boost.Python. According to this, I am doing it the right way... but I have a bunch of compiler errors. Here is a simple example I made trying to pinpoint the problem: #include "boost/python.hpp" using namespace boost::python; class number { public: number(int i) : m_Number(i...

operator overloading .net

What scenarios would you consider operator overloading in .net? ...

Example of overloading C++ extraction operator >> to parse data

I am looking for a good example of how to overload the stream input operator (operator>>) to parse some data with simple text formatting. I have read this tutorial but I would like to do something a bit more advanced. In my case I have fixed strings that I would like to check for (and ignore). Supposing the 2D point format from the link ...

Class Helper and Strings in Delphi Win32.

Is there any way with the current delphi to implement. a) String (as a class) with operator overloads (ie. +, =) b) Class Helper's so one could add custom string methods I gather the string is a native type so class helpers will not work without setting up a class etc. ...

c++ operator overload and usage

bool operator()(Iterator it1, Iterator it2) const { return (*it1 < *it2); } Can someone explain this function for me, thanks! is this means overload the operator ()? after overload this, how to use it ? ...

C++: Operator overloading of < for pointers to objects

Hello, I would like to compare two objects through their addresses. I tried operator overloading and it does not seem to work for pointers, but works for objects themselves. The following is the relevant code: class C { public: int x; }; . . . bool operator <( C *ptr_c1, C *ptr_c2 ) { return ( (*ptr_c1).x...

Unable to create an operator== for a generic type?

I've got a generic range class and I'm trying to add a comparison operator so I can test whether one range is equal to another. It fails to compile and I'm not sure how to fix the issues it's complaining about. Have I missed something obvious? Here's a snippet of the code: generic<typename T> public ref class Range { protected: T m_...

operator overloading in C++

Besides 'new', 'delete', '<<' & '>>' operators, what other operators can be overloaded in C++ outside of a class context? ...

c++ operator overloading memory question

In c++ you can create new instances of a class on both the heap and stack. When overloading an operator are you able to instantiate on the stack in a way that makes sense? As I understood it an instance that sits on the stack is removed as soon as the function is done executing. This makes it seems as though returning a new instance sit...

Is this good code? (copy ctor + operator=)

For one reason or another, I'm forced to provide both a copy constructor and an operator= for my class. I thought I didn't need operator= if I defined a copy ctor, but QList wants one. Putting that aside, I hate code duplication, so is there anything wrong with doing it this way? Fixture::Fixture(const Fixture& f) { *this = f; } Fi...

overloading operator<< for use with ostream

I am using CPPUnit to test a class in my program. This class (SCriterionVal) is somewhat unique because it has conversion operators for a lot of types (it's essentially a dynamic type value class). When I compile test cases that test it using CPPUNIT_ASSERT_EQUAL(), I get compilation errors about "operator<< is ambiguous" from one of t...

What is the accepted python alternative to C++ overloaded input stream operators?

In C++, you can do this to easily read data into a class: istream& operator >> (istream& instream, SomeClass& someclass) { ... } In python, the only way I can find to read from the console is the "raw_input" function, which isn't very adaptable to this sort of thing. Is there a pythonic way to go about this? ...