Questions tagged [inheritance]
Inheritance is the system in object oriented programming that allows objects to support operations defined by anterior types without having to provide their own definition. It is the major vector for polymorphism in object-oriented programming.
inheritance
42,719
questions
0
votes
0
answers
27
views
Error inheriting non pure virtual function from class that implement another class
In my code i have this three classes, i'm using the visual studio compiler and it's compiling without any error and runs fine.
But i don't need the methodes width and height in my interface IBrick, if ...
-2
votes
0
answers
55
views
Is there a way to make my compiler warn if my method-call explicitly calls up to a non-direct-parent superclass? [duplicate]
Background: After some careless refactoring, the following dumb mistake crept into my codebase, resulting in a somewhat-hard-to-track-down runtime misbehavior:
class Grandparent
{
public:
void Foo(...
1
vote
1
answer
72
views
How to provide a 'blanket implementation' of a static method for the derived class?
Consider this:
struct Base {
static Base make() { return {}; }
};
struct Derived : public Base {
// I _would_ want to have a `static Derived make()` automagically here
};
One approach to the ...
0
votes
0
answers
24
views
Lua: Assistance Needed in Using Inheritance in conjunction with case-insensitive metatables/metamethods? Doable?
I've been trying to wrap my head around utilizing inheritance with Lua (https://www.lua.org/pil/16.2.html and Case insensitive array in Lua as references) but also integrating a case-insensitive ...
0
votes
1
answer
33
views
Composable inheritance... how to add padding to inherited content?
I want to do some kind of Composable Inheritance. I need a parent composable with a Scaffold, and the children must have the inner content to the scaffold. How can I apply the innerPadding to the ...
0
votes
3
answers
91
views
Inheritance of C# functions and using reusability
I'm drawing a complete blank on what to actually call what I want to do (hence the difficulty I am having in trying to research it). But what I do have is this:
public interface IShapes
{
public ...
2
votes
1
answer
85
views
How to return smart pointers and covariance in C++
I am following this tutorial to understand how to return smart pointers and covariance in C++.
#include <memory>
#include <iostream>
class cloneable
{
public:
virtual ~...
-1
votes
0
answers
20
views
Need to extract a method to use in equals implementation with Hibernate DTO's
I am updating a Java project and had to add an equals() implementation 3 java DTO files (call them Child1, Child2 and Child3) which all extend the DTO Parent class. IntelliJ generated the following ...
4
votes
1
answer
94
views
Assign base object without changing inherited ones?
How valid is it to assign a new object to a base one, without changing the inherited ones?
The example below works as expected, but is it by chance?
This example is simple, but is there any situation ...
-2
votes
1
answer
54
views
When calling an inherited method from a derived class it tries to use the uninitialised fields of the base class [closed]
I have two classes. One called Agent, and the other called Player. Agent is the base class and Player is the derived class.
When calling the function SetHand() from the derived Player class, I run ...
0
votes
0
answers
14
views
Declaring an interface property as a derived type [duplicate]
Currently I have a series of services/repos that are allowing a generic of a custom type. I want to add a generic list to that interface such that when a class inherits the interface it can apply a ...
-1
votes
0
answers
34
views
invalid covariant return type for [duplicate]
Consider the following example, which is some part of the bigger codebase, in the getInstance() if I dont return a pointer to the derived class, i.e., just void or int or a different type, the ...
-1
votes
0
answers
32
views
Does a socket instantiated in a parent class belong to its child class?
I'm making a messaging service in java where I'm using sockets and object input/output streams. I wanted to make this as object oriented as I can (to learn OOP) so for the client side I'm making an ...
0
votes
1
answer
54
views
What are the differences between using mutiple or'ed typehints vs abc and an inheritance hierachy in Python?
Python is a dynamic language. This means that types are dynamic at runtime and Python makes use of the concept of Ducktyping.
What this means is that for any object x was can do
x.some_function()
x....
1
vote
1
answer
42
views
Inherit override-equivalent as different methods
Several methods from interface, super class or new method are override equivalent. I need to make different realization for each. Example:
public interface A {
int f();
}
public interface B {
...
1
vote
0
answers
30
views
how to use a foreingkey field in a Multi-table inheritance?
Currently the code is working for me, however in admin panel it is not displaying the information in the fields. I assumed that the information that had been entered in the parent table would be seen ...
0
votes
1
answer
46
views
"Error creating form in Unit...fmx: FMX datamodules not supported." when inherit from TDataModule descendant class
I have a problem (with sample project).
I have a TDataModule derived class to which I have added some properties and methods.
I wanted to make sure that it was possible to create a new instance of ...
3
votes
1
answer
48
views
Multiple constructors annotated with Lombok @Builder cause a problem?
This is my first question, so please feel free to correct anything that I missed writing this question:)
I am having trouble with using the @Bulider with my DTO objects.
I have an abstract class "...
-2
votes
0
answers
55
views
a constructer declared in a type with parametere list must have 'this' constructor inisializer error [closed]
I'm working on a C# project where I have an abstract base class Employee with a parameterized constructor Employee(string name). My derived class FullTimeEmployee has a constructor that takes three ...
0
votes
1
answer
34
views
Why is inheritance using constructor functions "hard to do properly" (MDN)?
The MDN's article for "Inheritance and the prototype chain", under "Different ways of creating and mutating prototype chains": "With constructor functions", gives the ...
0
votes
0
answers
44
views
How to alter WPF button color from the Code not user input (click) [closed]
I have a WPF application that allows users to pick a test to run. We have 3 tests called Test1, Test2 and Test3. All these tests inherit a model called TestModel. TestMoel contains common properties ...
-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 ...
2
votes
0
answers
66
views
Base class not recoginsed while using wild card generic
Why is the below not working?
A b1 = new B();
Function<? super B, ? extends A> function = x -> new B();
A apply = function.apply(b1);
It gives an error "Required type capture of ? ...
3
votes
1
answer
68
views
Why objects having instance of a class with private property in prototype throw when accessing private member?
Consider this code:
class Klass {
#priv = 42
get pub() {
return this.#priv
}
}
// these two correctly return 42
console.log(new Klass().pub);
console.log((new class extends Klass {})....
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 ...
1
vote
2
answers
37
views
Angular component inheritance: will @Component decorator metadata inherited?
I have a parent-component like this:
@Component({
template: "",
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ImYourFather {}
Now I also have two inheritance ...
5
votes
3
answers
170
views
Initialization order of inherited constructors
I have this example:
#include <iostream>
#define print(X) std::cout << X << std::endl
struct B1 {
B1(int _i = 5): i(_i) { print("B1 constructor"); };
int i;
};
...
-2
votes
2
answers
67
views
How do I create a member that can accept 2 very similar interfaces?
I currently have two classes that do exactly the same but have differences of a single member.
interface interfaceA {
VariationA getVariation();
}
interface interfaceB {
VariationB ...
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
):...
0
votes
1
answer
43
views
inherit constructor and factory in flutter
I'm learning flutter and I'm trying to turn requests results into more convenient objects, so I created the basic schema of a response (which is not supposed to be instantiated anytime) :
class ...