polymorphism Questions

4

Solved

I'm trying to understand a polymorphism but I don't understand why we need runtime polymorphism if static polymorphism works fine for calling members of a class. Like, suppose this was a problem. ...
Cordite asked 31/5, 2020 at 7:47

6

What is the advantage of making a private method virtual in C++? I have noticed this in an open source C++ project: class HTMLDocument : public Document, public CachedResourceClient { private: v...
Wentzel asked 31/1, 2010 at 5:39

7

Solved

I'm writing a module and want to have a unified exception hierarchy for the exceptions that it can raise (e.g. inheriting from a FooError abstract class for all the foo module's specific exceptions...
Pretender asked 30/3, 2009 at 5:4

9

Solved

I can find a number of discussions regarding this but no clear solution. Here are two links, although I will cover everything in my own question here. Github Issues Laravel.io discussion Simple ...
Autogiro asked 9/1, 2015 at 17:31

6

Solved

All the time, I find myself doing something like this: Animal *animal = ... if (Cat *cat = dynamic_cast<Cat *>(animal)) { ... } else if (Dog *dog = dynamic_cast<Dog *>(animal)) { ......
Hadleigh asked 2/4, 2014 at 20:54

3

Solved

I can not seem to make head or tails of this Raku error message I found while exploring grammars... Cannot resolve caller report(Array:D); none of these signatures matches: (Array @r) (Match $r) ...
Chartography asked 19/1, 2023 at 1:46

2

How do you set a default discriminator for each child class? For example, take this schema: components: schemas: Pet: type: object required: - petType properties: petType: type: string dis...

3

Solved

Consider the following code: trait Animal { fn make_sound(&self) -> String; } struct Cat; impl Animal for Cat { fn make_sound(&self) -> String { "meow".to_string() } } ...
Preposition asked 12/9, 2014 at 23:2

3

Solved

I'm trying to implement a "polymorphic" Input enum which hides whether we're reading from a file or from a stdin. More concretely, I'm trying build an enum that will have a lines method that will i...
Porbeagle asked 18/3, 2016 at 15:20

29

Solved

What is polymorphism, what is it for, and how is it used?
Obnoxious asked 23/6, 2009 at 8:14

2

Solved

I have as parent class : User.java , and 2 classes : FacebookUser.java and TwitterUser.java they are entities that returned depends on the type column in database using DiscriminatorColumn, I want ...
Rosabella asked 29/9, 2016 at 15:7

13

Solved

Is there a way to write OO-like code in the C programming language? See also: Can you write object-oriented code in C? Object-orientation in C Found by searching on "[c] oo".
Engrave asked 7/2, 2009 at 16:13

2

Solved

I have a multi-level polymorphic type hierarchy that I previously serialized using the data contract serializers. I would like to convert that to System.Text.Json using the new type hierarchy suppo...
Vincenty asked 28/11, 2022 at 17:45

5

Solved

EDIT: A better title for this would be: polymorphism for large collections of objects without individual heap allocations. Suppose that I have a base class Animal with virtual functions and some de...

11

Solved

Let's say we have a class foo which has a private instance variable bar. Now let us have another class, baz, which extends foo. Can non-static methods in baz access foo's variable bar if there is...
Miracidium asked 4/5, 2009 at 23:40

6

Solved

I would like to store instances of several classes in a vector. Since all classes inherit from the same base class this should be possible. Imagine this program: #include <iostream> #include ...
Budgerigar asked 8/1, 2012 at 13:0

2

Solved

I just started developing some app in Java with spring-data-mongodb and came across some issue that I haven't been able to solve: Have a couple of document beans like this: @Document(collection="...
Hipster asked 15/2, 2013 at 1:23

1

Solved

I am trying to get a composite index working between a polymorphic subclass and it's parent. Alembic autogenerate does not seem to detect Indexes outside of __table_args__. I can't use __table_args...
Cruzcruzado asked 6/9, 2022 at 14:49

2

I am an accomplished C programmer, and I have written an assembler and VM in C (https://github.com/chucktilbury/assembler (mostly working but not complete)) and I am thinking of porting it to C++ s...
Launceston asked 5/9, 2022 at 18:10

8

Solved

I think I understand the concept of virtual methods and vtables, but I don't understand why there is a difference between passing the object as a pointer(or reference) and passing it by value (whic...

3

Solved

I'm using XmlSerializer to serialize an object that contains a generic list List <ChildBase> Children {get;set} The problem is that each element derives from ChildBase which in fact is an abs...
Chic asked 29/10, 2009 at 11:41

1

There are 2 classes - a base class, and inherited class. I want the function print to be able print objects of both of these classes. Though the name of the function is similar in both cases, the s...
Taam asked 17/6, 2022 at 16:45

2

Solved

I have a setup like this: @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "dishName", defaultImpl = Food.class) @JsonSubTypes(value = { @Type(name = "frie...
Keven asked 6/3, 2015 at 9:44

2

I am using Jackson to parse JSON that I have no control over. The JSON looks like this: { "status":"0" "type":"type1" "info": { // additional fields } } My class looks like this public cla...
Lectra asked 12/9, 2013 at 6:57

10

Solved

"Replace conditional with polymorphism" is elegant only when type of object you're doing switch/if statement for is already selected for you. As an example, I have a web application which reads a q...
Strontium asked 1/2, 2011 at 19:8

© 2022 - 2024 — McMap. All rights reserved.