Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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 -

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 ...
6
votes
1answer
206 views

Overloading istream>> to read comma-separated input

I have the following very simple class: ...
4
votes
2answers
108 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
174 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. ...
3
votes
2answers
322 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
67 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 (...
2
votes
0answers
211 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 ...
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 <...
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 ...
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
2k 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
104 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
206 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
1answer
98 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
2answers
98 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
69 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
65 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 ...
3
votes
1answer
294 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
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 ...
2
votes
2answers
143 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 ...
3
votes
2answers
150 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 ...
1
vote
1answer
385 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 ...
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 ...
5
votes
3answers
400 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
407 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 ...
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, ...
7
votes
4answers
287 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 ...
2
votes
2answers
177 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 ...
4
votes
1answer
15k 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 ...
1
vote
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
667 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
76 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 ...
-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
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? ...
3
votes
1answer
201 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
94 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
106 views

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

I have one class Number (base class) and two child class Fraction and ...
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 ...
0
votes
1answer
1k views

Polynomial class C++11

Initial stage of implementation of the polynomial class. Essentially I need to implement the basic mathematical operations. Right now I have implemented just addition. Was wondering if this is a good ...
5
votes
3answers
2k views

Comparing Equals() method from MSDN

I've implemented the Equals() support for my class as follows: ...
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 ...
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 ...
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. ...
1
vote
1answer
36 views

Getting a table from an Excel worksheet

I need to get a table from an Excel worksheet. Sometimes I know the worksheet that contains the table, other times I might know it's going to be in one of a handful of worksheets, and still other ...