Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
86 views

How do you call non-virtual, non-const derived class methods from a unique_ptr to base?

I have a factory pattern that stores a series of different derived classes in a map of unique_ptr to base: class ForceFactory { private: using BuilderFunc = std::function<std::unique_ptr<...
Jay Iuliano's user avatar
-2 votes
1 answer
71 views

c++ problems with polymorphism and inheritance

I can't get why this code prints E::n() A::m() E::j() if i run (p4->n()).m(); #include <iostream> using namespace std; class A{ public: A() {cout << "A() ";} ...
lostH's user avatar
  • 21
0 votes
1 answer
26 views

Abstract class in a inheritance entity scheme (Spring boot) [closed]

I have a Many-to-Many relationship between the entities Booking and Resource. Equipment is a child of Resource. My question is can I declare Resource like abstract? If I try to insert a new booking ...
Fernando's user avatar
1 vote
0 answers
17 views

Can Typescript infer subtypes of parameters based on a dynamic variable accessing an object-literal with functions with a common parameter supertype? [duplicate]

I apologize for the most likely inappropriate terminology to describe the following issue. I am trying to implement a sort of "functional Strategy-Pattern" with an object literal in ...
plc-dev's user avatar
  • 55
1 vote
2 answers
77 views

How to prevent Javascript super constructor calling a method overridden by a derived class?

I'm new to JS and implementing a polymorphic class hierachy. It appears that within the super constructor (when called from a derived constructor), 'this' refers to the derived class, not the super ...
TreeTownGreen's user avatar
1 vote
1 answer
116 views

Classes with interface but different arguments, how to solve? C++

I need to call a set of functions, but what functions are to be called isn't known at compile time. The user decides what kind of calculations he is interested in and then the program takes that input,...
Tary's user avatar
  • 93
0 votes
1 answer
68 views

(De) Serializing list of objects containing polymorphic generics in C# .NET 8 with System.Text.Json

When trying to serialize a list where objects are derived types of generic and generic base, I end up with the error: System.InvalidOperationException: 'Specified type 'CSharpLanguageTestingApp....
Oli R's user avatar
  • 1
0 votes
0 answers
38 views

Angular polymorphic models

We are using Angular for frontend dev. Usually we have a unique model for a feature and using a status attribute to display buttons, read-only fields, visibility blocks etc. (predicates based on ...
Archange's user avatar
  • 519
-1 votes
0 answers
62 views

Is auto polymorphic? [duplicate]

I'm confused as to why this lambda function can print two different types here. Does this indicate that auto can also be polymorphic? https://godbolt.org/z/z55eWEndf #include <stdio.h> #include &...
xujh's user avatar
  • 41
1 vote
1 answer
79 views

Locally abstract type VS explicit polymorphism in polymorphic recursion context

Could you explain me why this program does typecheck let rec plop1 : 'a 'b 'c. 'a -> 'b * 'c = fun x -> (fst (plop1 ""), snd (plop1 1)) while this one does not? let rec plop2 (type ...
abitbol's user avatar
  • 507
0 votes
1 answer
28 views

Polymorphic Lazy loaded Type-Safe Vue Components

How can I switch between different Vue.js components representing the same view, while ensuring type safety and lazy loading on demand? Example scenario: you need to dynamically load several filter ...
husayt's user avatar
  • 15k
1 vote
2 answers
122 views

How to create nested variadic functions?

I can't and won't bore you with the details, but my system has these specific requirements: Actions must be called and registered at runtime. Each Action can have multiple targets, and these targets ...
fiqcerzvgm's user avatar
0 votes
0 answers
122 views

Pointer gives garbage values if using virtual inheritance

I have a storage class that stores void pointers (I know that is questionable design but I didn't design it) to arbitrary types of data. While writing a unit test, I noticed that I get a segfault when ...
DDDDDDDD's user avatar
2 votes
1 answer
80 views

Overriding derived virtual method in a templated class

I have the code below where I want foo to be implemented by the derived class but used within baseclass by bar methods. But I need foo to handle two cases where one of the inputs and the output type ...
Dominik Ficek's user avatar
0 votes
0 answers
16 views

How to accept argument using inheritance? [duplicate]

I understand that the parent class can be the type that hold the child class; For example: `Object o=new Student("stuname");` List<Object> l=new ArrayList<>(); l.add(3); l.add(&...
Echo Cheng's user avatar
0 votes
1 answer
62 views

Class that inherits from sf::Drawable cannot be use with std::vector

I use the SFML graphic framework to make a very small 2D game engine. Recently, I tried to convert the engine from a static library to a dynamic library, but a problem occurs. It seems like a class ...
J3hud's user avatar
  • 13
0 votes
4 answers
211 views

How to share functions between C++ classes when the member object they operate on is defined differently (stack vs heap)?

I have a situation where I have one class, A, which contains the same functions as class B, but A defines it's own object on the stack to perform functions on, whereas B obtains it's object externally....
metamorphosis's user avatar
0 votes
0 answers
86 views

Casted pointer does not get desired properties and methods for abstract parent class

I have a program where I instantiated an abstract parent class and cast a pointer of a child class (C-style type cast) to one of the parent class. When I looked up properties and called functions, for ...
openwld's user avatar
  • 914
0 votes
1 answer
41 views

Polymorphic deserialization of Multiple level inheritance through Jackson in Java [duplicate]

How do I deserialize the following example so that Jackson automatically provides me with the correct object public class vehicle { String vehicleType; } public class car extends vehicle { String ...
qstack's user avatar
  • 769
0 votes
0 answers
27 views

How to use polymorphism to dynamically create class in Flask with sqlalchemy?

I'm trying to process user input data in a form. Ad is the base class, Housing, ForSale, Job are its child. I want to create the appropriate class based on different input. Currently, I'm using if ...
kevin's user avatar
  • 55
6 votes
0 answers
79 views

Make a method final and use the base class implementation

I have a hierarchy of polymorphic classes. At some level in the hierarchy, I want to make the implementation of a virtual method final. Additionally, I just want to use the base class implementation. ...
michael3.14's user avatar
0 votes
2 answers
66 views

Prevent JSON.net to serialize derived type properties when declared as a base type [duplicate]

Given: class Mammal { public int Age { get; set; } } class Human : Mammal { public string Name { get; set; } } class Stuff { public Mammal Mammal { get; set; } } And var stuff = new ...
Node.JS's user avatar
  • 1,514
2 votes
3 answers
203 views

Does there exist a Haskell generalization of this two-pass scan algorithm that works for all two-pointer problems?

To make this question very precise and objective, I am looking for any nontrivial generalization other than "replace Int with some polymorphic numeric type". In this old SO question, the ...
lanf's user avatar
  • 509
1 vote
1 answer
76 views

Implicit casting / polymorphism with a Dictionary in C#

I've got a problem where I am not able to implicitly cast a Dictionairy<int, class> to a Dictionairy<int, interfaceOfClass> where I feel that this should normally be possible with the ...
Philip's user avatar
  • 69
0 votes
0 answers
30 views

undefined reference to the class derived from an abstract class [duplicate]

I have an abstract class 'Question' and four derived classes from it: 'SAQuestion', 'TFQuestion', 'OCQuestion', 'MCQuestion'. I use polymorphism, so I can use class pointers and make them refer to my ...
Beliy.'s user avatar
  • 9
0 votes
1 answer
64 views

Template inference when there are multiple possibilities?

I have the following pattern: struct Wrapper { vector<shared_ptr<BaseType>> data; template <typename DerivedType> add(const DerivedType& e) { data.push_back(...
Fran�ois's user avatar
  • 473
1 vote
1 answer
78 views

How to model a polymorphic relationship in Hibernate 6 for foreign entities with different key types?

I have the following tables (pseudocode): conversations id bigserial subscribers id serial asset_categories id smallserial requirements id serial requireable_type text requireable_id ...
davemyron's user avatar
  • 2,542
0 votes
1 answer
29 views

How to print the string name of a class that inherits attributes and methods from a parent class

I couldn't find a solution to this anywhere, but I've used a method in my parent class (Wallet) to print the name of the class when I call the method function in the script. The problem is that the ...
Dsafsfa's user avatar
  • 11
2 votes
1 answer
62 views

Unmarshall nested YAML in a struct with different nested objects but a without common method to satifsfy an interface

I looking for an elegant solution to unmarshall yaml with different kind of nested object without interface which requires to have a common method (polymorphism). Example 1 Source Consider the ...
Aurelien's user avatar
1 vote
3 answers
96 views

Polymorphic DI framework or setup for .NET?

The situation that I have is the following and albeit quite simple, it seems not to be supported (at least out of the box) for 2 DI frameworks that I tried. public interface IPlugin { // misc } ...
Stelios Adamantidis's user avatar
2 votes
3 answers
135 views

Laravel Eloquent parent with multiple polymorphic children

I've been trying to model a relationship in Laravel between a ShapeContainer entity and different shapes with unique properties, but a common Shape interface (with getArea and getPerimeter methods). I'...
Simeon Borisov's user avatar
0 votes
1 answer
54 views

Attempting to get rid of nested switch clauses but new to C# (Perhaps using Dictionary and Delegates) [closed]

Unity Game Engine has this nice methods to detect collisions: OnCollisionEnter OnCollisionStay OnCollisionExit All of them take a Collision object in order to implement logic on all of those cases. ...
Erparom's user avatar
  • 23
1 vote
2 answers
84 views

Define a common interface without dynamic polymorphism

In applications such as ray tracing, an entity can be one of several types, which all share a common interface. For example, a Material can either be a DiffuseMaterial or a ReflectiveMaterial, etc and ...
Kotaka Danski's user avatar
2 votes
2 answers
102 views

How to "mark" a function-like trait to be optionally executed in parallel?

Context I have a predicate trait. It takes some type T and returns a boolean value for it. trait Predicate<T> { fn evaluate(&self, t: &T) -> bool; } I also have evaluator that ...
Sun of A beach's user avatar
0 votes
3 answers
132 views

How to avoid calling a virtual function in destructor when the base class need to know info about the derived when destructing?

Currently I met with the following situation: I have a base class Base with an void* V member, it may be A*, B*, C* actually, and three (only three, fixed number) catagories of class will derive from ...
Nekomiya Kasane's user avatar
0 votes
1 answer
69 views

Handling Conditional `belongs_to` Associations with Different Foreign Key Types in Rails

I'm working on a Rails application where I need to manage a polymorphic association with different types of foreign keys based on the reporter_type attribute. The main challenge is that the foreign ...
Shreya Gupta's user avatar
0 votes
1 answer
59 views

c++: method operating on a set of instances including the object self

I have a C++ design which I think is ugly, because it is ambiguous. I have a set of multiple instances of a certain class A (or an inheriting type), which need to perform a computation. The result ...
mneuner's user avatar
  • 447
0 votes
0 answers
28 views

How to implement method correctly for a struct with AsRef<str> generic? [duplicate]

I have a following type: pub enum AppError<S: AsRef<str>> { ScenarioError(S, Option<S>), SystemError(S), } impl<S: AsRef<str>> AppError<S> { pub fn ...
muturgan's user avatar
  • 503
3 votes
1 answer
79 views

Method hiding instead of static virtual C++

I want to create a utility class (which are usually static) and combine it with OOP's abstraction. My question is: is it a good practice to use method hiding to combine abstraction with static, as C++ ...
Spleentery's user avatar
1 vote
1 answer
60 views

How to implement a polymorphic Newtonsoft.Json.JsonConverter?

Given the following polymorphic type hierarchy: [JsonConverter(typeof(PolymorphicConverter<Base>))] public record Base { private Base() {} public record A(string Value) : Base; ...
havarnov's user avatar
0 votes
2 answers
125 views

C++ - Use a parent class to prevent derivative classes from defining constructors?

I don't know if what I'm proposing in this question is a bad idea or not or even reasonable to ask because I don't have enough experience with C++ to know any better, but I digress for the sake of ...
Spring E. Thing's user avatar
1 vote
2 answers
78 views

C++ Multiple Inheritance: Implementing interfaces with overlapping virtual functions

I'm trying to design a class hierarchy in C++ where I have a base interface FooInterface with a pure virtual function foo(), and another interface FooBarInterface that should extend FooInterface and ...
HiroIshida's user avatar
  • 1,593
2 votes
1 answer
81 views

Can't deserialize a mongo db collection in a polymorphic way in Spring Boot

I have a mongo collection called "items" which contains jewelry. In each document of the collection I have a discriminator property "category" - which I'm using to deserialize the ...
miberg81's user avatar
0 votes
1 answer
90 views

type classes act as interfaces (??)

After reading about type classes in Haskell, I thought them as like Java interfaces You define a set of methods in your type class (Num) and any data/newtype(Foo) declared type, if it wants to be part ...
kichii112's user avatar
1 vote
0 answers
58 views

How can I use the result of a function which has multiple return types, without being warned about "Incompatible types in assignment"?

This question is in the context of Python 3.12 (so, making use of the latest type hinting features of the language) and the current version of mypy for static type checking. Consider the example ...
Erinaceous's user avatar
1 vote
1 answer
69 views

Which smart pointer to insert into linked list to maintain polymorphism?

I'm writing a simple compiler and I have a base class: class Instruction { public: virtual std::string get_name() const = 0; }; I create an instruction such as Compute: class Compute : public ...
Thomas Matthews's user avatar
-1 votes
1 answer
62 views

Access properties of child class in base class array

I want to access child class properties that only exist in the child class in an array of type base class (changed the example from animal to question) class Survey { Question[] questions } class ...
Kilian Reichart's user avatar
0 votes
1 answer
60 views

How can I create multiple class/enemy variations using my StateMachine in Unity using C#?

I have been following multiple sources to create my own custom StateMachine in Unity Engine, without any substates. I've managed to create a StateMachine that handles every basic, simple requirements ...
Halil Ibrahim Efe's user avatar
1 vote
0 answers
23 views

How to handle a DTO in both polymorphic and non-polymorphic endpoints with Jackson?

I work with SpringBoot 3.2 and kotlin. I have a usecase for a polymorphic api which I do with some jackson annotations. This already works: @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = ...
Christian's user avatar
  • 884
0 votes
1 answer
97 views

Calling own C++ template function in dylib ends up in identical one in other dylib on Mac

(Note: this is a major revision of the original question after I gained the insight that the original question was a red herring -- it didn't have any answers yet anyway.) I'm working on an OSX host ...
Carl Colijn's user avatar
  • 1,597

1
2 3 4 5
208