The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
3
votes
2answers
74 views

Two classes for avoid confusion when handling degrees and radians

Experimenting with operator overloading for the first time. Based on my reading, it appears to be a bit of a minefield. Have I fallen into any traps? ...
1
vote
0answers
25 views

Overloading both for (non) constant access [closed]

I'd offer a couple of iterator accesses to the class member, both constant and non-constant. I came to the following solution, but it seems to me far more verbose than needed. I'd like somehow to ...
2
votes
0answers
56 views

Python adding partialmethods to a class at compile time

I am writing a class for delayed operations on variables which are resolved at a later time. I am using pythons operator overloading but my class definition seems very boilerplatey. Is there a more ...
3
votes
3answers
330 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 ...
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 ...
7
votes
1answer
264 views
4
votes
2answers
123 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. ...
2
votes
2answers
188 views

Polymorphic implementation for == with CRTP

I'm trying to implement equality for all types that share same base. Consider std::vector<unique_ptr<Shape>> and that we want to check if a certain ...
-2
votes
3answers
40 views

Refactorizing overloads with the same scope but different calls [closed]

Well I have 3 methods that are overloads, but in it's scope has the same scope except one method call. ...
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 ...
3
votes
2answers
615 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 ...
2
votes
1answer
105 views

Operator overloading for Boost interval (vectors)

I am a complete newbie to C++ and programming in general. I need to write something for scientific purposes and as such, performance is crucial. I introduced two types, matrices and vectors with ...
2
votes
1answer
96 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 (...
1
vote
2answers
54 views

Generic function with same logic but different input structure

I have a data structure that looks like this: interface Node { originalWeight: number; currentWeight: number; } where both properties are floats between <...
2
votes
0answers
242 views

Function overloading in Python

Motivation As an exercise, I wanted to try implementing function overloading in Python 3, i.e. to implement a way of defining multiple functions with the same name and then calling the appropriate ...
7
votes
4answers
300 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 ...
3
votes
2answers
173 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 ...
4
votes
3answers
186 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 ...
1
vote
1answer
46 views

Overloading Java function (insert into binary tree)

I have a binary tree below and it seems to make sense to overload the insert() method. If insert() is called without a ...
1
vote
3answers
3k views

Cartesian/polar coordinates program

Can I get my program checked for efficiency? As in, see if there are better ways of writing my code, for example, making more efficient use of memory and/or security options like where to use ...
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.(...
1
vote
1answer
113 views

Get column of a matrix python with index operator

How can I refactor this code to generalize the argument parsing? I feel like this code can be better but I can't find a way. The usage syntax of the index operator is similar to the NumPy indexing ...
5
votes
2answers
257 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 ...
2
votes
2answers
112 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: ...
1
vote
0answers
70 views

Practice global operator new for my Fruit class and Apple derived class?

I want to practise global operator new/delete and new[]/delete[], how can I improve it? Here are one Fruit(Base) Class, and one Apple(Derived) Class. ...
5
votes
1answer
71 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 ...
4
votes
1answer
319 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, ...
5
votes
1answer
109 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 ...
2
votes
2answers
155 views

C++ String Non-Member Operator Overloading

This is a practice for operator overloading, I am well aware that some of these don't make sense. I am seeking review only on the code/practices, not the purpose. ...
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 ...
23
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 ...
1
vote
1answer
452 views

Overload binary operator for vector [closed]

I want to be able to construct and fill a vector of bytes using a stream (binary shift) operators. So I overloaded operator << (...). Here is the code I want ...
5
votes
3answers
493 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 ...
2
votes
0answers
440 views

Reference wrapper for functions overloadings and universal references

I have design a little class to allow to overload a function with universal references for a known type, but I'm not sure if that class will work as expected in any contexts. The indended purpose is ...
6
votes
1answer
7k 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 ...
3
votes
1answer
3k 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, ...
2
votes
2answers
178 views

Find combination of sets which sum up to a specified result

Example input : A) 1, 2 B) 2, 8 C) 7, 8 Required Result : 8, 10 The output from the program with this input should be A + C. Few notes : We can only combine 2 sets. There must ...
6
votes
1answer
17k 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 ...
2
votes
2answers
2k views

C++ operator overloading for matrix operations

Please check the code to see if there anything I can improve . Everyting is working as expected. matrix.h ...
4
votes
2answers
932 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 ...
1
vote
1answer
78 views

An iterator which behaves like an array with uniform values

I'm implementing an iterator which takes a single value and which you can advance for n times with a dereferencing yielding the single value - but before or after that range of n 'positions' you can't ...
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 ...
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 ...
0
votes
1answer
3k views

Add two fractions or two integers using template class and overloading

Question: Need to create three classes. Number Fraction Integer Requirements The first class should support “display”, “==”, and “+”. "Display" : This operation displays the Number itself in its ...
-1
votes
1answer
115 views

Using templates and function overloads to set DOM attributes [closed]

I'm making a library to build and manage a website. I want to control what gets to be inserted. For example I don't want to be able to insert ...
2
votes
3answers
3k 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? ...
3
votes
1answer
205 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
1answer
101 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 ...
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 ...
1
vote
1answer
107 views

Operator Oveloading: “+” and “==” for two classes

I have one class Number (base class) and two child class Fraction and ...