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,358
questions
0
votes
1
answer
39
views
The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter
I've been playing around with TypeScript (I'm still learning) and writing up a few test scenarios to better understand programming fundamentals.
export class Base {
readonly id: string;
...
-1
votes
0
answers
32
views
Polymorphism in Java Spring [closed]
I develop an application in Java Spring. I have an abstract superclass called AbstractPuzzle and I have its children called Wordle and Riddle(I have JOINED type of inheritance).
I get an ...
1
vote
0
answers
29
views
Complex multi level EF Core 8 inheritance issue
Please consider the following:
DB Context:
// DbContext.cs
public partial class OperationsDbContext : DbContext
{
public virtual DbSet<AnimalBase> AnimalBases { get; set; }
public virtual ...
0
votes
0
answers
21
views
OpenAPI Swagger with kotlin inheritence
How to deal with inheritence with Kotlin for Swagger targetted objects?
Just wondering if there is a way to do something like
@Schema(description = "Child.")
class Child(
aName: String
):...
2
votes
0
answers
41
views
Using Assumed Rank with Unlimited Polymorphic Issues
There must be something I'm misunderstanding.
I'm attempting to use an assumed rank unlimited polymorphic variable to store data. When I do this I either get access violations or corrupted data. I ...
0
votes
0
answers
23
views
Cereal archive called from DLL cause polymorphism not to work
I am a newbie to cereal and lately I ran into an odd issue,
I have my serialization code inside an external DLL, in the code I use cereal's polymorphism functionality, when trying to invoke the ...
0
votes
0
answers
38
views
create object type based on base type member function return value
I am implementing a loadbalancer that should choose balancing strategy based on some logic:
class LoadBalancer{
public:
bool get_backend_cpu_info(){// some complicate logic involve member ...
-1
votes
0
answers
56
views
Compiler misidentifying/unrecognising type [duplicate]
I have the following class with constructor:
command.h:
#include "./robots.h"
enum class CMD { //...... };
class CommandTemplate {
//.....
public:
virtual std::unique_ptr<...
16
votes
1
answer
1k
views
How does C++ select the `delete` operator in case of replacement in subclass?
Let's assume I have the following code (https://godbolt.org/z/MW4ETf7a8):
X.h
#include <iostream>
struct X{
void* operator new(std::size_t size)
{
std::cout << "new X\...
0
votes
1
answer
100
views
How do you use polymorphism with Go maps?
I'm curious on what kind of patterns should used in Go for such cases. So let's suppose, you have a Request struct that holds some information for making an HTTP request, along with the parameters ...
0
votes
0
answers
16
views
Efficient design solution for handling dynamic marking schemes with multiple levels and subjects
We're developing a grading system for a school with multiple levels (e.g., elementary, middle school, high school) and various subjects within each level (n subjects < 200). The challenge is that:
...
2
votes
3
answers
154
views
In C++, compared to final or not virtual function, what is the advantage of CRTP?
I'm new to learning modern C++ programming. I have read many blogs and questions but haven't found the answer of this question. In C++, compared to final or not virtual function, what is the advantage ...
0
votes
1
answer
74
views
Strange inheritance behavior with base class
I hope someone can help me since can't quite understand how it is possible that the following code can work.
I have a base class with some classes that derive from it.
Each derived class has its own ...
5
votes
2
answers
108
views
How to change the type of a polymorphic record using lenses?
In the following code snippet, how do I write the toRecordWrite function such that it can work with any DbRecord with similar type-level mechanics, eg. UserPoly id createdAt updatedAt email username ...
0
votes
1
answer
52
views
Accessing Private Members of Derived Class through Base Class Pointer with Virtual Function in C++
I have a scenario in C++ where I'm accessing private members of a derived class through a base class pointer, and it seems to work without any errors. Here's a simplified version of the code:
#include ...