All Questions
Tagged with polymorphism abstract-class
247
questions
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
votes
1
answer
58
views
Is there a way for a base class to require derived classes to have a comparison function to an object of the derived same class?
I have a homework assignment, and a small part of that assignment asks for a abstract parent “Movie” class with three concrete subclasses: “Comedy,” “Drama,” and “Classical.”
Each subclass will never ...
0
votes
1
answer
72
views
How to encourage devirtualisation of an unused abstract base class?
I have a shallow class hierarchy (minimal reproducible code example at the bottom) where I'm using an abstract base class to hold mostly common logic between a bunch of related classes, with a virtual ...
0
votes
0
answers
28
views
Class loader issue - duplicate class definition for name -LinkageError
I have created a class with the following attributes and methods.
I think there is a fundamental issue with my implementation. When I import this signalwrapper class into my test framework, I receive ...
1
vote
1
answer
63
views
Why is it allowed to have a container of an abstract class as a function parameter?
Recently in our code base we have found a function that didn't compile in one specific compiler.
The scenario was something like this:
#include <vector>
#include <iostream>
class Base{
...
-1
votes
1
answer
97
views
Is it a good practice to inherit a generic class from a non generic class, in Java?
I have this code:
public abstract class Course<T extends Student> {
private String name;
private int months;
private int capacity;
private static List<Student> students = ...
0
votes
0
answers
74
views
Cannot instantiate the abstract class
Here are my projects files compiled with VS:
Init.h
#pragma once
#include <iostream>
#include <memory>
#include "Ishare.h"
using namespace std;
class Init {
private:
std::...
0
votes
1
answer
145
views
How to call a method of super class from parent class. How to call the same method from interface?
I am learning java and I am trying to recreate a scenario where A class is extending an abstract class and also implementing an interface. Each abstract class and interface have a same method defined ...
2
votes
1
answer
202
views
Why can we call abstract method from an abstract class before sub-class initialization
We can initialize an abstract class through initialization of a concrete sub class. Therefore, should be able to call the abstract methods of an abstract class only after the initialization of a ...
1
vote
1
answer
495
views
Container with unique pointer to an abstract class
I've been trying to create a factory method which allocates subclasses entities from a given abstract class, which I'll name Shape for simplicity. It looks something like this:
Shape* makeChild(Type ...
0
votes
1
answer
46
views
Decide on class at runtime at write all fields to file in Java
I have a system that writes reports to a file in json. All three reports share fields like id and value but each report has additional fields that are not shared. I want to decide at runtime which ...
0
votes
1
answer
120
views
how to implement polymorphism using abstract class for getting, saving and deleting three different product types in php
how can I implement polymorphism using an abstract class for handling product saving, deleting, and showing for three different product types?
there are three product types: DVD, Furniture, and Book
...
0
votes
0
answers
89
views
How to invoke the method in abstract class that has been overriden in the subclass in java?
In this below code:
interface I1 {
void m1();
}
interface I2 {
void m2();
}
abstract class A implements I1, I2 {
public void m1() {
System.out.println("Inside A: m1()");...
0
votes
1
answer
86
views
How to store different class objects without loosing information [duplicate]
This is my base class where I have method PrintInfo which will be overriden in the child classes.
class Place
{
private:
std::string Name;
int Population;
std::string County;
public:
Place(std::...
0
votes
1
answer
108
views
How do I code an ID number whose first digit changes depending on the subclass created?
I'm working on an assignment in my computer science course and I am stuck on a certain part where I'm asked to generate ID numbers with specific rules and I am not sure how to go about it. Here are ...