Questions tagged [overloading]

The terms overloading and overloaded may refer to: - Constructor and method overloading, a type of polymorphism where different functions with the same name are invoked based on the data types and number of the parameters passed - Operator overloading, a form of functional or method overloading where the action being overloaded is an operator, such as + or -

Filter by
Sorted by
Tagged with
48
votes
2answers
3k views

Named operators in C++

A post by Yakk alerted me to the idea of named operators in C++. This look splendid (albeit very unorthodox). For instance, the following code can be made to compile trivially: ...
31
votes
4answers
1k views

Standardly deviated Fibonacci

I'm new to C++ (about 4 weeks with no prior programming experience in other languages) and am writing a program that's supposed to do the following: Define an array of 100 sequential numbers of type <...
24
votes
6answers
5k views

C++ string operators

I'm trying to practice my C++ on my own; At the moment I'm trying to implement the concept of operator overloading making my own string class/function. I think I handled this correctly; the code ...
11
votes
2answers
7k views

Generic Calculator and Generic Number

.NET does not support generic numbers. It is not possible to enforce a generic method with generic argument T that T is a number. The following code will simply not compile: ...
9
votes
1answer
441 views

Multiple dispatch decorator classes in Python

This is based on my first review and the suggested points in "Multiple dispatch decorator in Python": ...
8
votes
1answer
380 views

Avoid duplicated += -= operator code

In C++ (and C++11), classes defining a + and += operators often define a - and ...
7
votes
1answer
13k views

Review of 2d Vector class

I'll keep this short. I've never actually done professional C++. I don't really know any of the 'best practices'. I'd like to get some review on a simple class that I've made. My Vector2d.h file: <...
7
votes
4answers
290 views

Formatting date depending on current date

I have two screens where I show a message creation time and date. Initially, there was only one screen and I should always show time and show date differently depending on difference between today and ...
6
votes
3answers
4k views

Money class with overloaded operators

I have program that uses a Money class which has several constructors for different methods of input and overloaded operators to add, subtract, and compare values. ...
6
votes
3answers
11k views

Basic complex number class

As part of my C++ training, I wanted to create a basic complex number class for basic complex number calculations. The class should have the following: constructor (non explicit, for implicit ...
6
votes
1answer
216 views

Overloading istream>> to read comma-separated input

I have the following very simple class: ...
6
votes
2answers
5k views

EF lookups and enums

I have a lookup table "RequestTypes" that has the following data: ...
6
votes
1answer
6k views

Calculator - C++ operator-overloading

I am new to object-oriented concepts. The following is my attempt at creating a basic calculator using class and operator overloading concepts. Please review it for improvements. Also, how do I make ...
6
votes
2answers
4k views

Single Linked-List Implementation in C++

I haven't done much C++ coding the last few years, so I've been reviewing in preparation for upcoming interviews. I wrote a minimally functional singly linked-list. I'm using my implementation for ...
5
votes
3answers
2k views

Comparing Equals() method from MSDN

I've implemented the Equals() support for my class as follows: ...
5
votes
2answers
1k views

Overloading operators in PhoneCall class

I am trying to understand the concepts of friend functions, overloaded operators, and inheritance in C++. I am very confused on the specifics used for coding, since ...
5
votes
1answer
95 views

Class Iteam: Answer to one of the unsolved Stack Overflow Qes

I would like to improve my skill on C++ concepts and I came across the following question in StackOverflow, which has been directly asked by a StackOverflow-user without any preliminary attempts.(...
5
votes
1answer
762 views

Overriding GetHashCode and Equals

I'm creating a class to wrap a list of Mask and I'd like to know if I'm overriding the GetHashCode() and ...
5
votes
1answer
68 views

Overloading __getitem__() for two key types in Python

I've got a collection of users with two types of IDs (a_id, b_id) where one is a positive integer and the other is a six-letter string. For my collection class, I'd like to be able to look up users ...
5
votes
2answers
143 views

Overloading email sender utility class methods take single or array arguments

I'm writing a simple utility class for sending an email. I'm not sure what's the proper way to present this to a consumer. Should I force them to use an array in ...
5
votes
2answers
208 views

Overriding operator delete/new to check correct pairs of (non-)array variants

A legacy project I am maintaining in my freetime uses overrides of operator delete / operator new. These overrides over-allocate ...
5
votes
3answers
420 views

C++ mathematical vector class

I plan to implement a simple simulation in C++, which requires mathematical vectors. The following header file contains the complete vector class with all it's method definitions. By overloading ...
5
votes
2answers
931 views

Providing const- and non-const overloads of a strstr() implementation

In a question about reimplementing strstr(), I posted an answer. I pointed out a need for const- and non-const versions of the function, and provided ...
5
votes
1answer
106 views

Author class, with constructor validations and rich comparisons

I wrote the following Author class in Python for a project I'm working on. I wanted to make sure that the rich comparisons and the methods I used to validate the constructor parameters were done ...
4
votes
3answers
180 views

Basic binary number container

Summary: a templated class, whose main purpose is to store a binary representation of a decimal number. I choose array of booleans as a storage, since bitset was forbidden. One of the requirements was ...
4
votes
2answers
686 views

Python-style string multiplication

When people migrate from Python to C++, they're often bothered by the fact that C++ strings don't support multiplication like Python's strings do. std::string does ...
4
votes
2answers
109 views

C++ Pixel/Array manipulation libs

I was tired to always perform pixel manipulation one by one, so I started to create my own templated header to perform computation over pixel (RGB, or RGBA), but I also make it for ND for some cases. ...
4
votes
1answer
16k views

C++ operator overloading for matrix operations - follow-up

This is improved code after I some issue in pointed by @Edward in the last question: C++ operator overloading for matrix operations This work assignment in operator overloading .I need to use ...
4
votes
1answer
2k views

Overloading operator ->* for smart pointers

I am implementing a smart pointer class template and I want to overload operator ->* (even if it’s rarely done). I came across Scott Meyer’s article Implementing ...
4
votes
1answer
50 views

Program containing several bitset based classes including chars, strings, ints and a base bitset class

This is by far the biggest project i've ever made. The main goal was just to make a bitset class but it expanded into making several classes based off of that main bitset class. Some things I would ...
4
votes
1answer
3k views

Custom operator new and operator delete

In our embedded application, we have to replace ::operator new and ::operator delete to call a special ...
4
votes
1answer
1k views

Implementing C++ boolean function objects with logical operator combinations

I want to make a C++ object hierarchy of "classifiers", which can be composed together via logical operators into a single classifier that implements the whole logical combination. This is actually ...
3
votes
3answers
318 views

A hash-signature-type which tests on comparing against normal strings

I decided to throw this together today figuring it would be cool to add to my repertoire. Before we always had performed this "task" externally. Find the value we want to compare, hash it and compare ...
3
votes
2answers
383 views

Class to store and manipulate Cartesian coordinates and vectors

I have made a C++ class to manipulate 3D vectors in Cartesian coordinates. However, the performance of my class is much slower (about 2.5x) than simply using something like ...
3
votes
2answers
4k views

C++ code to find distance between line and point

So I made this simple program that allows users to construct points and lines and then return the smallest distance between a given point and a line. In doing so I have used some OOP concepts and ...
3
votes
2answers
154 views

Encapsulation preserving operator= overloading in C++

I have made a facility to perform operator= dispatching to a member setter function. The purpose is to enable accessing members (like using ...
3
votes
2answers
1k views

Emulating __uint128_t

I developed a lot of code locally with __uint128_t only to find out that it is not available on the target platform. I am now trying to write my own struct that ...
3
votes
1answer
96 views

Overloaded applyRestrictionsToCriteria(…) methods

We want to refactor two methods that are exactly the same, except for one difference: one takes an org.hibernate.Criteria and the other ...
3
votes
1answer
2k views

Functions asking for user input, with default prompts

I succeeded in the first part of the exercise, this attempt is the second part. I am not sure I have accomplished the goal, and would appreciate the input of more knowledgeable minds. As always, ...
3
votes
1answer
202 views

Recursive flattening of Swift sequences - an overly complicated approach

I recently read and answered Martin R's Recursive flattening of Swift sequences and continued to play around with the code until I arrived at something that was both pretty cool and possibly an ...
3
votes
2answers
72 views
3
votes
1answer
655 views

Implementing binary output to a file in C++11

I would like to have a class which supports outputting bits into a file. This is what I came up with but I fear there are many poor decisions. Should I inherit from a ...
3
votes
1answer
299 views

Operator Overloading Tricks in C++

This method is taken from Syntactic Aspartame. This is my attempt at a generic version. The goal is to create an operator X <NAME> Y where name is anything, ...
3
votes
1answer
51 views

Addition operators for length units

I'm writing some code that helps me deal with units better, by having a user defined type for things like Metres, Centimetres ...
2
votes
3answers
363 views

Overloaded handlers for various configurations retrieved from a database

I have a switch statement that references different configurations based on data pulled from a database. Each iteration of configuration has variations in what needs to be enabled/modified. I've set ...
2
votes
2answers
102 views

C++ limiting a method for an rvalue caller, an expression evaluator example

There are many ways to implement a math expressions evaluator (I focus here just on the evaluator part, without any parsing). I want to explore a certain implementation to support the following main: ...
2
votes
1answer
2k views

C++ wrappers for execv(3)

Calling execv(3) (and similar functions) in C++ can be problematic. execv expects an array of const pointers to non-const ...
2
votes
3answers
2k views

Functor to compare two floats with tolerance

What do you think about this implementation of 2 floats comparison functor considering how tolerance is introduced? ...
2
votes
2answers
762 views

Grails overloaded controller workaround

I had an overloaded method, but Grails doesn't allow overloaded methods in controller actions. The overloaded method looked like this: ...
2
votes
1answer
74 views

C++ - Astar search algorithm using user defined class

The objective of the post is to improve design and improve command on C++. Given a map, start point and end point, the shortest path to end point from the start point has to be found out using Astar (...