Skip to main content
Filter by
Sorted by
Tagged with
Best practices
0 votes
3 replies
94 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
  • 176
3 votes
1 answer
129 views

As I understand it, std::polymorphic<T> and std::indirect<T> are const-propagating wrapper types for an owning pointer to a T object, where the target of the pointer is copied with the ...
dumbass's user avatar
  • 27.2k
3 votes
2 answers
92 views

I have a ProductLandedCost model with a morphToMany relationship to various other models: Warehouse, for example: class Warehouse extends Model { // ... public function productLandedCosts(): ...
Aaron Dunigan AtLee's user avatar
2 votes
3 answers
119 views

I have three processor classes that share a common interface for polymorphic behavior using std::variant and std::visit. Each processor has a processData() member function that internally consists of ...
Ali Sedighi's user avatar
2 votes
2 answers
209 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
225 views

I'm building a Qt wrapper for RtMidi. As starting point I created two separate classes QMidiOut and QMidiIn that wrap RtMidiOut and RtMidiIn. I don't want to duplicate code for the common methods (e.g....
NoobNoob's user avatar
  • 114
5 votes
1 answer
140 views

Consider this Haskell code that compiles successfully: {-# LANGUAGE RankNTypes #-} -- Applies a polymorphic function to different types, expecting 3 constraints applyToMany :: (forall a. (Show a, Eq ...
Thomas's user avatar
  • 6,364
0 votes
0 answers
65 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
196 views

I'm playing around with OOP in Python, and I have something like this: class Person: def __init__(self,name, age): self.name = name self.age = age self.hobbies = [] ...
Ranao's user avatar
  • 33
0 votes
2 answers
69 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
164 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 delete ptr, ptr being a pointer to a polymorphic object (...
lobelk's user avatar
  • 531
1 vote
1 answer
111 views

Consider these model classes: [JsonPolymorphic(TypeDiscriminatorPropertyName = "$type")] [JsonDerivedType(typeof(A), typeDiscriminator: nameof(A))] [JsonDerivedType(typeof(B), ...
aepot's user avatar
  • 4,864
3 votes
1 answer
99 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 specialized for all T* template ...
Enlico's user avatar
  • 30.3k
1 vote
0 answers
72 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 yaml_tag for ...
9Lukas5's user avatar
  • 91
3 votes
2 answers
114 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
129 views

I am developing a simple logic-gate simulation. For each logic gate type the following class is implemented: class Gate { public: explicit Gate(); virtual ~Gate() = default; virtual void ...
Placeblock's user avatar
1 vote
1 answer
102 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
66 views

I have this class hierarchy: public abstract class Device { public string Code {get;set;} } public class Motor: Device { public int SerialCode {get;set;} } public class Battery: Device { ...
Luka's user avatar
  • 4,211
1 vote
4 answers
153 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
69 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 of Store (e.g., DenseStore, SparseStore) uses a different internal data ...
Andrea Novellini's user avatar
2 votes
4 answers
217 views

I have a simple c++ base class and two derived classes: class base; class der1; class der2; class base{ public: virtual void act(base*); // ignore for now virtual void print(){ cout &...
AccidentalFourierTransform's user avatar
3 votes
1 answer
176 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
145 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 Dog, both with a speak() method. I ...
Hassan Ali's user avatar
0 votes
0 answers
36 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 function ...
Bet Co's user avatar
  • 29
0 votes
1 answer
43 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
163 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 variable which is present in every type. To store different types I am using ...
phinz's user avatar
  • 1,647
0 votes
0 answers
36 views

Current models: class Task(PolymorphicModel): pass class DownloadTask(Task): pass New models: And now i want to do add a new layer called VirtualTask: class Task(PolymorphicModel): pass ...
Jorge's user avatar
  • 125
0 votes
3 answers
138 views

In order to use C++20's format capabilities with custom types, we have to provide template specializations of std::formatter for every type we want to format. The nice thing about this approach is ...
Raven's user avatar
  • 3,658
1 vote
1 answer
64 views

I need a Parent-Child class using CRTP for performance reasons. Something like this: template<class CHILD> struct Parent { }; struct Child1 : public Parent<Child1> { }; but I need a way ...
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: class Base { public: virtual ...
Miro Kropacek's user avatar
2 votes
1 answer
59 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.3k
2 votes
1 answer
230 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
  • 137k
1 vote
0 answers
105 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
68 views

This code doesn't compile: use indexmap::IndexMap; use either::Either; type Atom = Either<IndexMap<String, u64>, Vec<String>>; fn flatten(atoms: Vec<Option<Atom>>) ->...
gust's user avatar
  • 965
1 vote
1 answer
98 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,515
0 votes
1 answer
235 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: type Mutation { createAnimal(input: ...
imsilversurfer's user avatar
1 vote
2 answers
145 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 class where there's 2 ...
zecuse's user avatar
  • 361
0 votes
1 answer
86 views

I have an entity that has invoices and offers. class Entity < ApplicationRecord has_many :invoices, dependent: :restrict_with_error has_many :offers, dependent: :restrict_with_error Invoices ...
Ricky883249's user avatar
0 votes
1 answer
76 views

I have a base class A, and two subclasses B and C which inherit from A. I would like to be able to store a union of B and C in an std::vector<A*>, but it seems that it may not be possible. Here'...
ERSUCC's user avatar
  • 70
0 votes
0 answers
30 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: import "reflect-metadata"; import {...
IgorArnaut's user avatar
0 votes
0 answers
41 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: father: id ...
Antoine Drobecq's user avatar
3 votes
1 answer
124 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 instance of B: #include <iostream&...
Featherball's user avatar
-4 votes
1 answer
70 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
96 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 : public override void PrimaryInteraction() { if (...
Oroitz Lago Ramos's user avatar
2 votes
0 answers
67 views

I have two classes extending the same parent class; AbstractVaultConfiguration. My base classes @override the same two methods from AbstractVaultConfiguration which are clientAuthentication and and ...
tharika's user avatar
  • 21
3 votes
1 answer
140 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: class MenuNode { public: MenuNode(const ...
akasaka's user avatar
  • 322
0 votes
1 answer
68 views

Using Signed Global IDs with Polymorphic Select Fields in Rails Forms: My models: class Comment < ApplicationRecord belongs_to :commentable, polymorphic: true end class Post < ...
user29559775's user avatar
-1 votes
1 answer
65 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
165 views

Let's say I have the following classes: public abstract class Animal { public abstract void talk(); } class Dog extends Animal { @Override public void talk() { System.out.println(&...
montag's user avatar
  • 11
0 votes
0 answers
23 views

here is my Value Class @Data @NoArgsConstructor @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = TYPE, include = JsonTypeInfo.As.EXISTING_PROPERTY, visible = true) @...
Priya Lorha's user avatar

1
2 3 4 5
209