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.
40,697
questions
0
votes
0
answers
9
views
C++ Template DEEP Inheritance
I have the following 2 mingw compile erros:
error: expected template-name before '<' token
error: expected '{' before '<' token
On the line class Size3 : public Size2{
How can I fix it?
...
0
votes
1
answer
21
views
Python class inheritance dynamic class variable
This is what I want to do:
class Base:
_type = None
name: str = _type.name
class a(Base):
_type = UnityType
a_instance = a()
a_instance.name # Expecting UnityType.name to be some string....
0
votes
0
answers
13
views
Why can't I obtain the (relative) address of a virtual member for an object?
I've read:
How can a C++ base class determine at runtime if a method has been overridden?
and
get the real address(or index in vTable) of virtual member function
and the answers really bug me. Suppose ...
0
votes
1
answer
39
views
Return Base class shared pointer using derived class C++
I have a an interface:
/*base.hpp */
class Base {
protected:
Base() = default;
public:
Base(Base const &) = delete;
Base &operator=(Base const &) = delete;
Base(...
-3
votes
0
answers
24
views
Calling objects of other class into main class [duplicate]
Here - staff is the super class/base class
teacher,typist,officer are the sub class/derived class
regular and casual are the derived class of typist.
I am facing an issue related to on calling the ...
0
votes
1
answer
23
views
Pythonic way of passing on methods when using composition instead of inheritance
Suppose I have a library with something like the following, where Person is a user-facing class.
class SwissArmyKnife:
def open_bottle(self):
"""...etc...."""...
0
votes
1
answer
43
views
How to access a ruby variable in another class?
How can I access the name variable in the game class, when I assign it in the Player Class? I am slightly confused about classes inheritance and scope. (Ruby)
class Game
attr_accessor :name
def ...
0
votes
0
answers
33
views
How do you dynamically add a method to an existing object when the method you want to add uses the "super" keyword in its body?
Suppose you want to add a method f() to an object myObj where f() uses the super keyword in its body. Eg:
function f() {
return super.foo() + 10
}
myObj.foo = f
Well, this doesn't work, because ...
1
vote
0
answers
33
views
C++: function argument of instance of any subclass of given base class
I'm learning C++, this is a noob question...
I have a base class Life:
#include "GameObject.h"
class Life : public GameObject {
private:
public:
Life(int x, int y);
virtual ...
0
votes
0
answers
19
views
How to inherit from, or override elements of, the Default style for a WinUI 3 control?
I am trying to learn how to use Styles most effectively in WinUI 3 (from WindowsAppSDK 1.1.1) but I'm having difficulty getting simple inheritance to work.
Consider the NavigationViewItem class. I'd ...
1
vote
2
answers
31
views
Javascript Prototype changed but still accessing old methods
I was learning inheritance and Prototype chaining. I was stuck after seeing this behaviour of resetting the constructor function's prototype inside the function itself.
On instantiating
Case
...
0
votes
1
answer
28
views
Python deepcopy not copying right
I have a class NodesGIS(GeoDataFrame) (NodesGIS therefore inherits from GeoDataFrame). I also have a class WaterNetworkModel whose attributes include an instance of NodesGIS called nodes_gis.
However, ...
0
votes
1
answer
37
views
How to get a list of classes that extend from a base class in Kotlin?
consider following classes structure in Kotlin:
open class Base {
...
}
class A : Base() {
...
}
class B : Base() {
...
}
...
class Z : Base() {
...
}
How would I go around getting a ...
1
vote
1
answer
23
views
ArrayList of Objects That Inherit from Parent Classes in Java
I have a class, controlBase, that is inherited by other child classes. How can I make a list of any of these child classes?
I have tried:
private ArrayList<? extends controlBase> controllers = ...
1
vote
2
answers
31
views
How to test a protected member from multiple inheritance in GoogleTest?
Imagine I have a Foo class which contains a protected member. Foo is my template base class.
Then I have a Bar class, which inherits from Foo.
The protected member will be private within Bar.
I need ...
1
vote
1
answer
17
views
When I inherit from frozenset, I get TypeError: object.__init__() takes exactly one argument (the instance to initialize)
I want to inherit from frozenset and change the constructor. What I actually want to do is to make a singleton fronzeset, but instead here I'll provide a simplified example:
class B(frozenset):
...
1
vote
1
answer
35
views
Best way to choose different child class to create new instance based on a boolean
Hi my question is simple.
I have 3 classes, BaseObject, and GoodObject + BadObject that extends it:
public class BaseObject {
// some properties
}
public class GoodObject extends BaseObject {
// ...
0
votes
0
answers
33
views
How to inherit in Javascript
So I am working on a project where I use Prismarine/Mineflayer to set the actions of bots in Minecraft.
I deploy the bots using Docker. I have a class called Practice, which is basically an action the ...
-2
votes
1
answer
26
views
Rails many-to-many associations on single-table-inheritance child models with join tables
I have a Keyword class that has multiple different categories/types through STI, as described below
class Keyword < ApplicationRecord
end
class Keyword1 < Keyword
end
class Keyword2 < ...
-2
votes
2
answers
37
views
Python - Having some troubles with the super function and importing [closed]
I have been trying to transition to Python recently but my brain isn't working well with it.
I really can't find what is the problem.
window.py
import tkinter as tk
class Window(tk.Tk):
def ...
0
votes
0
answers
17
views
It shows an error when executing the inheritance constructors "actual and formal argument lists differ in length" [duplicate]
I have been doing some dummy executions and I tried to execute this but shows no argument error.
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main&...
0
votes
3
answers
46
views
C++ Child Class Change Parent Class's Constructor
Modified the question a bit, thanks for your help on this!
Is there a way to change Parent's constructor(e.g. change the value of protected field) when initialize the Child class.
For example, I have ...
1
vote
1
answer
40
views
How does {all: initial} work? Problem with default values
Why does paragraph inherit properties from div such as:
line-height and text-align.
If values for these properties are:
normal -> for line-height
[i.e. font-size = 16px (initial / default value) * ...
-2
votes
2
answers
47
views
Downcast generic class
I've got a generic class based on some type, and a child class which specifies that type. However, the Swift compiler doesn't seem to be able to downcast the parent class with the correct type to the ...
0
votes
0
answers
13
views
How to store properties of polymorphism identity with SQLAlchemy?
In the following example, the type column of the parent class (employee) is stored as a string and defines the polymorphism identity.
How to store properties for the type, e.g. an "...
0
votes
1
answer
26
views
what could i be doing wrong? am using turtle on my pycharm and my turtle.write method is not displaying on the screen
below are my scoreboard.py and main.py codes but after i click run, i can't see my score printed on the screen.
from turtle import Turtle
ALIGNMENT = "center"
FONT = ("Courier", 14,...
0
votes
0
answers
23
views
Reverse Lookup for Inherited Models in Django
I have several Django model definitions. There is a parent class contains a foreign key to another class, and there are multiple model classes that inherit from the parent.
class Foo(models.Model):
...
0
votes
0
answers
38
views
What should I implement/assign when extending the PyGame.sprite.Group?
I have a grid of sprites, so I was thinking that I should create a Group subclass that stores the sprites as a 2D array, but properly interacts with the sprites as elements when I call .draw(), etc., ...
0
votes
1
answer
43
views
Parent-Child casting after reading back from JSON
I have a parent, lets call it Bike that has a name and a color.
public class Bike(){
String name;
String color;
}
I have 2 children
public class TrickBike extends Bike(){
...
...
...
0
votes
4
answers
42
views
java - class attribute type change with inheritance
I have a MyClass which has an attribute of type MyAttribute.
This class is inherited by MySubClass which has an attribute of type MySubAttribute.
MySubAttribute is a subclass of MyAttribute :
class ...
1
vote
2
answers
79
views
C++ Specific override of template class member function
I would like to have a class that implement multiple interfaces of same template class as follow:
template<typename T>
class Interface
{
public:
virtual void foo(const T&) = 0;
...
0
votes
0
answers
8
views
Pass Main Window Attributes to Modules within a package
Good evening!
I am dabbling in python, and am running into the following issue.
On the one hand I have a MainWindow developed in QtDesigner, and a module main_window.py that loads the window and ...
0
votes
1
answer
93
views
(C++) Two classes with some common function. Cleanest way to code
I have two classes that has some common functions and some different functions.
Let's say
class Red{
public:
void funcA();
void funcC();
}
class Blue{
public:
void ...
-1
votes
0
answers
32
views
polymorphism using pointer vs reference in c++ [duplicate]
I was wondering what would happen given the following code:
class Base
{
public:
Base () { std::cout << "Base ctor" << std::endl; }
~Base () { std::cout << "Base ...
0
votes
0
answers
34
views
Java: Is there a way to make a parent interface's default methods override a parent class's methods automatically in a child class?
I have a class that extends another class and implements an interface. The parent interface has a default method with the same signature as a method in the parent class, like below.
class ParentClass {...
-3
votes
0
answers
35
views
Pass attributes to python package [closed]
I am dabbling in Python, and am running into the following issue. On the one hand I have a MainWindow developed in QtDesigner, and a module main_window.py that loads the window and various labels, the ...
0
votes
0
answers
19
views
Call inherited class function from base class [duplicate]
I'm doing a menu in which each item open a different page. The id of the selected menu item correspond to the panel id.
I think I'm doing it the wrong way but is it possible to do this like that :
...
0
votes
0
answers
38
views
Is there a way to write a method so that Method<A>(C obj) compiles? [duplicate]
Is there a way to write a method so that Method<A>(C obj) compiles in C#?
I want to exercise implicit type parameters to make the code cleaner to write and read. I have a model where Activities ...
0
votes
1
answer
47
views
C++ change base's member variable and print it from derived class
The idea is:
I've 2 classes, one named Print with only one method called printName, and other class named Human with variable name. I want printName to print whatever the name variable in the Human ...
0
votes
1
answer
57
views
C++ abstract method, different parameters in different inheritances
I have a base class from which several classes should inherit.
The base class is supposed to be a simple interface, which one inherits for a easy implementation/ for passing data into a library.
...
0
votes
1
answer
19
views
I have a problem with spring boot inheritance classes
I have a user class which is a supper class and a student class a subclass of users. I don’t have an error in the code but I don't why it does not make tables in the database when I remove "...
0
votes
1
answer
41
views
Inheritance With Blazor Component Classes
I'm trying to implement a simple heirarchy for the classes behind my blazor pages, but for some reason I keep getting a build error.
What I've implemented is a simple way to update breadcrumbs from ...
0
votes
0
answers
15
views
Django Validation - Use Parent field validator and have subclass provide values
I have an abstract Parent model, and the subclasses inherit a field that has a validator. The validator takes in a list, and I would like each child to provide it's own list to validate against. I ...
3
votes
2
answers
50
views
Dart Inherit class and Use it in functions of the parent class
I want to make a parent class which use ChangeNotifier. And from this class, I want to create two separate inherited classes that will provide list data to some parts of the app, and each will have ...
1
vote
1
answer
32
views
Combine two classes from a table per hierarchy inheritance structure in Entity Framework
We're are using the table per hierarchy inheritance technique with Entity Framework.
I'll take the example classes from this page as the basic classes: Table per Hierarchy Inheritance - The Model. ...
-4
votes
1
answer
55
views
what is Hybrid inheritance , is it mixture of hierarchical, multiple and multilevel inheritance?
Can anyone help me with Hybrid Inheritance. I have seen many tutorials and also researched on google, but still I find it difficult to accept it that it is just mixture of multiple and multilevel ...
-1
votes
1
answer
30
views
using private variable of a class in a methode of a subclass
public class B {
private int y ;
public B(int y){
this.y = y;
}
public int gety(){
return y;
}
}
public class C extends B{
int y,z;
public C(int y, int z ...
0
votes
1
answer
35
views
what is the exact subclass of superclass structure? why this code not work as my thought?
interface Test{
public void test1();
public void test2();
}
class TestParent implements Test{
public TestParent(){}
@Override
public void test1(){
System.out.println(&...
0
votes
2
answers
47
views
How to pass variable to base class
Consider the following Python code (Python 3):
I have a class Signal comprising all the functions signals of all different kinds should be able to perform.
For each kind of signal, I create a new ...
0
votes
1
answer
33
views
How to call different class factory fromJson constructors via a variable in a parent (abstract) class method
I have an abstract class Listicle with a method, fetchItem() that includes
var item = Stock.fromJson(itemMap);
But I want to be able to use this method in various child classes, say in addition to ...