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
10,359
questions
-1
votes
1
answer
68
views
How to call a child method after casting an instance from parent to child class?
If I have a class B that inherits from class A and overrides one of its methods, and I have, in TypeScript:
const a: A = new A();
(a as B).toto();
Why is the toto() method that will be called the one ...
1
vote
1
answer
44
views
Polymorphic return type for child classes
I want to make an abstract class with a pure virtual function process.
process should return a variable of type Result:
class Base {
public:
class Result {
public:
int a = 1;
...
1
vote
2
answers
71
views
C++ multiple inheritance- class method running twice
I have an exercise to practice multiple inheritance and polymorphism and something is not going well.
The exercise includes 4 classes I need to build:
Creature
char * name
int age
int ...
-1
votes
2
answers
63
views
Polymorphic behavior of derived class objects in C++ STL list [duplicate]
I am storing objects of base and derives classes (Account, StudentAccount, EmployeeAccount) in an STL list and process them with STL Iterator. The dynamic polymorphic behavior of objects is not ...
0
votes
0
answers
27
views
Unexpected vTable look-up for non-virtual method in C++ [duplicate]
The code snippet below explains the problem:
class base_obj_with_virtual_func
{
public:
int variable_int;
virtual void print_name() { std::cout << "Base obj " << this <...
0
votes
0
answers
24
views
How swift virtual tables are implemented in case of calling super from subclass
Suppose we have a class and it's subclass. We know that virtual table for second class has methods from superClass with changed addresses for overridden methods, and added methods from subclass is ...
0
votes
1
answer
37
views
Locust polymorphism with class as argument
I'm writing Locust scripts and want to extend a base class. There are two values (dto_class and api_suffix) that are different from one sub-class to another. Everything else is shared
locust_base.py (...
0
votes
0
answers
61
views
How to specialize the return type of a method in Kotlin
I want to implement a specific persistence in Kotlin, where I need to wrap the object to be persisted; yet, I still want to access some part of the persisted (generic) object in a type-safe way. How ...
2
votes
2
answers
64
views
How to generate an array of given size, with one field populated?
I would like to create a function that given a value of any type, a dimension of the one-dimensional array and the column to set, will return a one-dimensional array filled with null values except for ...
0
votes
1
answer
39
views
Subclassing a generic Kotlin class with type constraint
I'm running into problems combining subclassing polymorphism and generics (ad-hoc polymorphism) in Kotlin.
Here are my type definitions:
interface State
interface StatefulContainer<out S : State&...
0
votes
1
answer
48
views
How to reduce boilerplate code by generics
There are few structs which conform to common protocol:
protocol StateMachineState {...}
struct VideoMode: StateMachineState {
func transit(state: PhotoMode) -> Transition? {
...
2
votes
0
answers
61
views
CoreData: Fetching all child entities for a common attribute using polymorphism
I have a Core Data model with an abstract entity called Shape. Shape is a parent entity of Cube, Pyramid, Prism, Cylinder, and Sphere. Each of these individual shapes inherits the volume attribute ...
3
votes
2
answers
81
views
In python, how can/should decorators be used to implement function polymorphism?
Supposing we have a class as follows:
class PersonalChef():
def cook():
print("cooking something...")
And we want what it cooks to be a function of the time of day, we could do ...
0
votes
0
answers
43
views
Declaring parent and child classes in Java [duplicate]
I'm a beginner to Java and I just had a few questions when calling methods from parent and child classes.
Let's say I have a parent class called "Pets" and a child class called "Dog&...
0
votes
1
answer
75
views
Why can't I use a row-polymorphic variable?
Take a look at this PureScript code:
type MyOtherProps = (value :: String)
type MyProps = (a :: String)
a
:: forall props phantom allProps
. Union MyProps MyOtherProps allProps
=> Union ...