overloading

Vector sorting: swap overload

I would like to overload swap function for std::vector of primitive types / objects. The reason is a slow sorting of vectors containing big objects using std::sort. Here is the simple but not working example. #include <vector> #include <algorithm> class Point { private: double x, y; public: Point(double xx, double yy) : x(xx), y...

Is there a way to overload the regex binding operator `=~` in Perl?

I am working on a small DSL that uses the nomethod fallback for overloading to capture the operators used on the overloaded values. This is similar to the function of the symbolic calculator described in overload's documentation. This works fine for the standard comparison operators, but consider the following: my $ret = $overloaded =...

virtual function redefinition hides other overloaded functions of same name from another base class

Ok, I'm using virtual functions, overloaded functions, and multiple inheritance. Of course this doesn't turn out well. The scenario: Class base1 has a virtual function that needs to be specified by its child. Class derived derives from two parents base1 and base2, and should use base2's existing functionality to define base1's virtual ...

new/delete "override" vs. "overload"

I always thought... overriding means reimplementing a function (same signature) in a base class whereas overloading means implementing a function with same name but different signature ... and got confused because sometimes people just don't care about the difference. Concerning new/delete: Are they overloaded or overridden? An ide...

C# - How can I "overload" a delegate?

First, I was reading some forums and the help in MSDN and all says that a delegate can't be overloaded. Now, I want to have something like this: public delegate void OneDelegate(); public delegate void OneDelegate(params object[] a); public void DoNothing(params object[] a) {} public void DoSomething() { /* do something */ } private ...

Normal function not overwriting template function.

Hi, I have to use an external library, but am getting a "multiple definition error" from following template function and its explicit specialization, if it gets called with a std::string. template <typename T> void foo(T& value); template <> void foo(std::string& value); even if I change the 2nd function to void foo(std::string& va...

Is it possible to overload the ShowDialog method for forms and return a different result?

EDIT: This method actually works great and I asked it then found the solution later. I added the correct call in the overloaded ShowDialog() method (it's not exacly an overload, or even an override, but it works just the same. My new question is the one at the bottom. I have a form in which you click one of three buttons. I have define...

How to choose between one big method with passive overloads and a bunch of small overloads, each one doing a small amount of work?

Hi, There are two ways to implement overloads. The first one is to do everything in one method/constructor and call it from other overloads, which leads to longer method bodies. The second one is to do the minimum in each overload, thus having a code sometimes difficult to navigate and to understand which overload does what. For exampl...

Changing semantics of subclass methods in java

I've recently learned like 3 new languages and I'm starting to get them confused. I haven't worked Java in doing anything particularly complex (outside of android) in a couple years. I'm having trouble remembering if this is possible: I'm subclassing ArrayList mainly so I can keep the arraylist ordered. I'm trying to override the add(ob...

PHP Automatic Properties / Overloading

I am writing some PHP. I have several classes that do not declare any properties, public or otherwise. I have a custom mySQL class that fetches objects from mySQL and sets property values for the newly init'd PHP object like so... while ($row = mysql_fetch_assoc($result)) { foreach($row as $key => $value) { $this->{$k...

node.js - overloading functions

Is there a way to overload functions in node.js similar to _noSuchMethod_ https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/noSuchMethod? Thanks ...

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

php best practice for validating setter when overloading class properties

Hi, I have a class that uses the __set magic method. One of the properties for the class can only be set with a certain range of string values, the best example I can think of is the mysql datatype ENUM('value_one','value_two','value_three'). Would I place conditional statements within the __set method to distinguish between which pro...

C# Generic overloading of List<T> : How would this be done?

The StringBuilder class allows you, in what I consider to be a very intuitive way, to chain method calls to .Append(), .AppendFormat() and some others like so: StringBuilder sb = new StringBuilder(); sb.Append("first string") .Append("second string); The List class' .Add() method, on the other hand, returns void - so chaining calls ...

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 can I get around this limitation of overload resolution in Scala?

Hi, all, In Scala, the interaction of overloading and implicit argument resolution seem to make it impossible to make the following code usable. trait Bijection[A, B] extends Function1[A, B] with Unapply[A, B] { self => def apply(a: A): B def unapply(b: B): A } sealed trait Unapply[A, B] { def unapply(b: B): A } object Bijectio...

PHP Indirect modification of overloaded property

Hi, i have this simple class: class A { var $children=array(); function &__get($name) { if($name==="firstChild") { if(count($this->children)) $ret=&$this->children[0]; else $ret=null; } return $ret; } } By accessing the "firstChild" property it should return its ...

C# linq FirstOrDefault()

I select one double value from IEnumerable, how can i overload FirstOrDefault() function, to return null on default, instead of zero, iwant something like: double? x = from ... .FirstOrDefault(); i now i can catch exception, and write double? x = null, but i have 20 variables, and its not the way ...

Can't I define defaults if I define multiple overloaded constructors in Scala?

I've defined multiple constructors, with some default argument values in all of them. Looks correct (I can't see any ambiguity), but Scala (2.8) compiler complains: multiple overloaded alternatives of constructor define default arguments Does it mean that I can't define default values for overloaded constructors at all? Let me ill...

C++ Linker error iostream overloading

i get 2 linker errors when trying to compile my program which includes these two files (causing the problem, in particular the lines in bold) and i'm new to C++ so excuse my ignorance. Assignment1.obj : error LNK2001: unresolved external symbol "public: class Vector __thiscall Vector::operator^(class Vector)" (??TVector@@QAE?AV0@V0@@Z)...