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,725
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 ...
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
445
views
Python return type hint of subclass [duplicate]
I have a class method in Base class:
class Base:
@classmethod
def foo(cls): -> ????
return [a list of cls()]
class Sub(Base):
...
How should I define ???? to receive hint ...
1
vote
1
answer
427
views
Inheritable custom class constructor in python
How can I implement a custom constructor (class method) that is inheritable in python?
The following minimized example might give an idea:
from dataclasses import dataclass
from typing import Type, ...
1
vote
2
answers
1k
views
Type hint nominal inheritence bug Expected type 'Tuple[A]', got 'Tuple[B, ...]' instead
Consider the following :
from typing import Tuple
class A(object):
def __init__(self):
pass
class B(A):
def __init__(self):
super(B, self).__init__()
def foo() ->...
3
votes
2
answers
2k
views
Type hinting an instance of a nested class
I have a class structure that looks something like this:
class Base:
class Nested:
pass
def __init__(self):
self.nestedInstance = self.Nested()
where subclasses of Base each ...
2
votes
2
answers
565
views
How to annotate parent classmethod so that child methods return an instance of themselves?
I have a parent class BaseBlob that has several child classes LimitedProofId, ProofId, TxId. The parent class implement a deserialize class method that should return an instance of itself.
I also have ...
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 ~...
286
votes
9
answers
69k
views
What does it mean that Javascript is a prototype based language?
One of the major advantages with Javascript is said to be that it is a prototype based language.
But what does it mean that Javascript is prototype based, and why is that an advantage?
-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(...
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
0
answers
219
views
Python Generic[T] - typehint inherited nested classes
After a few rewrites due to cluttered code, I now have a setup that involves a set of BaseClasses and multiple inherited classes thereof such that
class Base:
class Nested: ...
class Nested2: ...
...
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 ...
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 ...
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 ...