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.

polymorphism
0 votes
1 answer
39 views

Why is dynamic dispatch not working within a template function?

I have the following code. There is a base class (Node) and a derived class (NumberExprNode) that each have a virtual equality method. #include <vector> #include <memory> #include <...
Dean DeRosa's user avatar
0 votes
1 answer
40 views

display method not compiling in Main JAVA

I can't figure out how to call the display method from shape class to the Main method. This is for an assignment, and we're not supposed to change what's written in Main, so the problem has to come ...
sufferingThruSchool's user avatar
1 vote
1 answer
19 views

How to move logic from runtime type matches to inherited classes without bloating the classes

I learned F# before C#, so I am unused to inheritance and do not understand its best practices. As I understand, the nearest object-oriented equivalent to the discriminated union (the "one of&...
Lyndon Gingerich's user avatar
-3 votes
3 answers
86 views

Why can’t a superclass call a subclass’s methods?

I’m a computer science teacher at a high school, and I’m teaching polymorphism in Java. My students asked me this question, and I didn’t have a good answer. Let’s say I have an Employee class. Also, I ...
Navarun Jagatpal's user avatar
0 votes
1 answer
47 views

How to call derived type methods from vector of base type stored in a different class?

say I have some class foo that has a vector of pointers to another class Bar and a LogBarVec() method that logs each Bar's internal type: class Foo { std::vector<std::unique_ptr<Bar>> ...
gerfg grgr's user avatar
0 votes
1 answer
75 views

When is it appropriate to assign a unique_ptr to a shared_ptr?

This is a follow up to the question that was asked here: Does C++11 unique_ptr and shared_ptr able to convert to each other's type? and more specifically the top voted answer. The snippet that caught ...
Sailanarmo's user avatar
  • 1,181
1 vote
1 answer
81 views

Polymorphism in Swift - Function override

There is a base class: class Base { func foo<S: Base>(to value: S) { print("Base class foo") } } and a derived ones from Base: class One: Base { func foo(to value: ...
Martin Kopecký's user avatar
0 votes
0 answers
57 views

Assigning std::make_unique<derived> to unique_ptr<base> failed

I'm trying to use polymorphism to implement different working mode, but there's something wrong with my implementation and I always get the same error: error: no match for ‘operator=’ (operand types ...
ToumaKazusa's user avatar
1 vote
1 answer
52 views

Idiomatic approach to query hierarchical of heterogeneous data

Edit: Maybe my problem is much more simple than I initially thought. My problem is in fact how to query complex objects (with nested objects) in relational databases. Maybe I just need to query each ...
Senna Sanzo's user avatar
0 votes
0 answers
67 views

How to combine type-heterogenous data with type-generic algoritms in iteration?

I wrote some ODE Solvers in rust that are generic. I hope to gain two things by the generics: efficient code generation and compile time checks. I then have a heterogenous collection of initial value ...
LudvigH's user avatar
  • 4,331
0 votes
0 answers
35 views

Polymorphism of Address Model in Laravel

Given I have the three Models User, Venue and Address (example taken from Address - Polymorphic association). A User has one Address. A Venue has one Address. A User/Venue may use the same address, ...
Anton's user avatar
  • 23
1 vote
2 answers
49 views

Initializing map of polymorphic function pointers

I'm doing a personal project which boils down to a task management command line tool. The idea is to take some of the concepts I've been using in higher level languages and apply them to C++, as well ...
Pedro Barbeira's user avatar
1 vote
2 answers
58 views

Jackson (de-) serialization hashmap with different object types

I am currently programming a game in Java, and I am having a problem with saving the entities data in Jackson. I need to (de-) serialize a HashMap with different subclasses of a superclass. E.g. I ...
NoNameIdea's user avatar
3 votes
2 answers
74 views

C++ Runtime polymorphism calling unexpected override when multiple classes are inherited

I am trying to create a GUI system with C++11 where, perhaps like Godot, every "node" has a very specific purpose such as grouping other nodes, drawing a rectangle, or detecting when a ...
CreeperCrafter979's user avatar
2 votes
0 answers
60 views

Access address of derived class data member in mixin constructor

In my code I have a system as outlined by the following code: // Base class to make derived objects polymorphic struct Base { virtual ~Base() = default; }; void registerData(int*) {} template &...
chrysante's user avatar
  • 2,635

15 30 50 per page