Skip to main content

Questions tagged [polymorphism]

In computer science, polymorphism is a programming language feature that allows values of different data types to be handled in a uniform manner.

Filter by
Sorted by
Tagged with
3 votes
1 answer
121 views

I am trying to clarify the relationship between Method Overriding and Polymorphism in Java. From my understanding, overriding happens when a subclass provides its own implementation of a method ...
thunder_bow's user avatar
5 votes
1 answer
212 views

Consider the following example (demo): ...
Juliean's user avatar
  • 1,760
Best practices
0 votes
3 replies
100 views

I'm struggling to finalise the design of my C++17 library. One of the primary goals is to use runtime polymorphism to allow users to extend or rewrite default features of the library for their own use ...
josh_eime's user avatar
  • 196
5 votes
1 answer
161 views

As I understand it, std::polymorphic<T> and std::indirect<T> are const-propagating wrapper types for an owning ...
dumbass's user avatar
  • 27.3k
3 votes
2 answers
100 views

I have a ProductLandedCost model with a morphToMany relationship to various other models: ...
Aaron Dunigan AtLee's user avatar
2 votes
3 answers
122 views

I have three processor classes that share a common interface for polymorphic behavior using std::variant and std::visit. Each ...
Ali Sedighi's user avatar
2 votes
2 answers
220 views

I am trying to implement a Parent and Child class. The Parent class would start a thread and run a routine function. The Child class would override the routine function if needed.This seems perfectly ...
Zhiyong Li's user avatar
Best practices
1 vote
6 replies
235 views

I'm building a Qt wrapper for RtMidi. As starting point I created two separate classes QMidiOut and ...
NoobNoob's user avatar
5 votes
1 answer
141 views

Consider this Haskell code that compiles successfully: ...
Thomas's user avatar
  • 6,364
0 votes
0 answers
76 views

I have created a very simple demo project with one controller endpoint: Spring Boot 3.5.6 Springdoc 2.8.13 This was working much better in Spring Boot 2.7.x Full project here: https://github.com/...
Aslak's user avatar
  • 139
-1 votes
3 answers
201 views

I'm playing around with OOP in Python, and I have something like this: ...
Ranao's user avatar
  • 33
0 votes
2 answers
70 views

I don't understand why my class that extends an abstract class (which implements an interface) does not override the interface's single method. I get this error when I try to compile: MyIntListImpl ...
user27630372's user avatar
0 votes
0 answers
170 views

I am aware that calling delete this in a member function is not UB in itself. In fact, compiler is doing the very same thing when one calls ...
lobelk's user avatar
  • 531
1 vote
1 answer
121 views

Consider these model classes: ...
aepot's user avatar
  • 4,896
3 votes
1 answer
101 views

In The C++ Programming Language - 4th edition, in §25.3 at page 731-732 Bjarne Stroustrup shows a possible implementation of a Vector template class that's been ...
Enlico's user avatar
  • 30.4k
1 vote
0 answers
90 views

I've tried to use kotlinx.serialization with the third party Yaml plugin from @charleskorn. In the past I already did something with Python using pyyaml, where I explicitly set a custom ...
9Lukas5's user avatar
  • 91
3 votes
2 answers
119 views

Given a base/derived class polymorphic relationship (established below via the virtual destructor), if I explicitly (C-style) cast a pointer-to-a-base object to a pointer-to-a-derived object, is this ...
Nathan Commons's user avatar
1 vote
2 answers
136 views

I am developing a simple logic-gate simulation. For each logic gate type the following class is implemented: ...
Placeblock's user avatar
1 vote
1 answer
109 views

I'm designing a .NET Core application using EF Core with a MySQL database, following a Table-per-Type (TPT) inheritance strategy. I have a base Report class with several derived types such as ...
Kafkaa's user avatar
  • 89
0 votes
0 answers
84 views

I have this class hierarchy: ...
Luka's user avatar
  • 4,211
1 vote
4 answers
156 views

My app crashes when I try to pass the base class as lpvoid then typecasting back to the base class, but works fine if I use a different method by passing the pointer to the base class as a function ...
Sempai-Dami1's user avatar
1 vote
1 answer
76 views

I'm working on a C++ project where I have an abstract base class Store that represents a container of Bin objects. Each subclass ...
Andrea Novellini's user avatar
2 votes
4 answers
225 views

I have a simple c++ base class and two derived classes: ...
AccidentalFourierTransform's user avatar
3 votes
1 answer
181 views

I'm attempting to make a game in C++ where pieces will move around a gameboard. In our team, we're trying to be good and use as much modern methodology as we can, given we've gotten rusty and now have ...
Force Gaia's user avatar
3 votes
1 answer
155 views

I'm learning Object-Oriented Programming in C++ and trying to understand polymorphism with base class pointers. I created a base class Animal and a derived class <...
Hassan Ali's user avatar
0 votes
0 answers
45 views

I'm debugging a performance regression in a hot code path and found that V8 is deoptimizing a function that uses closures in a monomorphic way. Here’s a simplified version of the pattern ...
Bet Co's user avatar
  • 29
0 votes
1 answer
47 views

I'm trying to create a simple simulation with shapes drawn on the screen. I've heard that it's good practice to separate the logic from the rendering, but I'm still not sure how to handle this ...
StaryNaBetonie's user avatar
2 votes
3 answers
189 views

I want to store objects of different types in a std::set and rely on std::set's sorting to later access them by some key ...
phinz's user avatar
  • 1,879
0 votes
3 answers
162 views

In order to use C++20's format capabilities with custom types, we have to provide template specializations of std::formatter for ...
Raven's user avatar
  • 3,668
1 vote
1 answer
66 views

I need a Parent-Child class using CRTP for performance reasons. Something like this: ...
intrigued_66's user avatar
  • 17.6k
0 votes
0 answers
74 views

Today I have found an interesting problem. Base is basically a class with well-defined and stable API with virtual functions encouraging to redefine their behaviour:...
Miro Kropacek's user avatar
2 votes
1 answer
61 views

I'm reading Associated Types with Class, and I'm running into code that doesn't seem to be compilable. Is it just a typo in the paper, or is that things have changed a lot since 2004, when the paper ...
Enlico's user avatar
  • 30.4k
2 votes
1 answer
240 views

I am designing a certain part of a library and considering whether or not to use polymorphic value types of some kind . If you don't know what those are and what the motivation for them might be, see ...
einpoklum's user avatar
  • 139k
1 vote
0 answers
119 views

Please excuse me for how long this question is. I tried to shorten it as much as possible while still listing all of the various things I've tried and the problems I've run into. I have a state ...
DavidTriphon's user avatar
1 vote
1 answer
70 views

This code doesn't compile: ...
gust's user avatar
  • 965
1 vote
1 answer
100 views

I am learning oop in Fortran. And I wonder about the interest of overloading type bound procedure when the type of an argument is not known at compile time. Let me explain, step by step my problem (...
Stef1611's user avatar
  • 2,535
0 votes
1 answer
282 views

I'm using Spring GraphQL with graphql-java and want to leverage the new @oneOf directive introduced in GraphQL 2022. Here's a simplified version of my schema: ...
imsilversurfer's user avatar
1 vote
2 answers
150 views

I'm limited to C++17. I need to make a tree structure (not necessarily binary) that can be deep copied into 2 independent clones. Currently, I have an interface Node...
zecuse's user avatar
  • 371
0 votes
1 answer
91 views

I have an entity that has invoices and offers. ...
Ricky883249's user avatar
0 votes
1 answer
82 views

I have a base class A, and two subclasses B and C which inherit from ...
ERSUCC's user avatar
  • 70
0 votes
0 answers
31 views

I have these models: https://pastebin.com/5d5mvPgF. So I've created an abstract Realty class and Apartment entity class which inherits Realty. Data source: ...
IgorArnaut's user avatar
0 votes
0 answers
42 views

I want to create a relationship between parents (which can be Mother or Father models) and their children (Son and Daughter models). For exemple purposes, they are defined like this: ...
Antoine Drobecq's user avatar
3 votes
1 answer
130 views

I have the following minimal reproducible example where it seems that my unique-pointer-containing object B is not allowed to contain a unique pointer to another ...
Featherball's user avatar
-4 votes
1 answer
72 views

I want to create a routine function in my project. I've created it in Laravel 10 with Alpine, Tailwind, Livewire and Flowbite. enter image description here enter image description here enter image ...
Viviane Le Hegaret's user avatar
1 vote
2 answers
97 views

I'm a student programmer and we are learning to use unity. I have this problem in C#. So I have a weapon class and a chil named gun. On weapon : ...
Oroitz Lago Ramos's user avatar
2 votes
0 answers
70 views

I have two classes extending the same parent class; AbstractVaultConfiguration. My base classes @override the same two methods ...
tharika's user avatar
  • 21
3 votes
1 answer
141 views

I am writing a UI framework for a microcontroller, in which I want to do a hierarchical menu system. For that in particular I have the following classes: ...
akasaka's user avatar
  • 322
0 votes
1 answer
71 views

Using Signed Global IDs with Polymorphic Select Fields in Rails Forms: My models: ...
user29559775's user avatar
-1 votes
1 answer
71 views

I’m really confused about what polymorphism in OOP actually means. Everyone explains it differently, and I’m not sure which definition is correct: In some places, polymorphism is explained as dynamic ...
Ado's user avatar
  • 55
1 vote
4 answers
177 views

Let's say I have the following classes: ...
montag's user avatar
  • 11

1
2 3 4 5
209