Skip to main content
Stack Overflow for Teams is now Stack Internal: See how we’re powering the human intelligence layer of enterprise AI. Read more >
Filter by
Sorted by
Tagged with
Best practices
1 vote
0 replies
25 views

Calling a method from a parallel mixin in Python without breaking MRO or responsibilities

I am working on a multifunctional quite old game bot with the followng implementation: There are tons of mixins in different files/folders (each inherits GameBase). Each mixin: - uses attributes + ...
Vova's user avatar
  • 609
14 votes
3 answers
1k views

The 'this' pointer in multiple inheritance of a C++ class

#include <iostream> using namespace std; class Base1 { public: virtual void foo() { cout << "Base1::foo\n"; } int b1_data = 1; }; class Base2 { public: virtual void ...
SuperBald's user avatar
  • 333
-1 votes
1 answer
141 views

Python and multiple inheritance [duplicate]

I tried to understand multiple inheritance behaviour with Python, so I tried something but I have no idea why the output of my code is what it is. (I know that diamond inheritance is bad, but was ...
SinisterMJ's user avatar
  • 3,519
-3 votes
1 answer
73 views

How do I implement multi-inheritance DUPLICATE method in Java?

I have an 8-level hierarchy of classes in Java. This is useful so each abstract class implements methods that are common in the whole sub-branch of the tree. That's working fine. However, after going ...
Joe DiNottra's user avatar
  • 1,083
1 vote
2 answers
197 views

What does the presence of the keyword `virtual` really do in the context of inheritance?

There are lots of posts on the internet about virtual inheritance in C++. Typically these posts say something like this: Virtual inheritance solves the Diamond Inheritance Problem Virtual inheritance ...
user2138149's user avatar
  • 18.6k
0 votes
0 answers
115 views

Multiple inheritance in C++ with ambiguous (or duplicated) virtual function names [duplicate]

Let's start with a code example: #include <iostream> class Base1 { public: virtual ~Base1() {} virtual void f() { std::cout << "Base1.f()" << std::...
user2138149's user avatar
  • 18.6k
-1 votes
2 answers
110 views

C# - Derived class that can inherit either one class OR another

This question is NOT about inheriting two classes. This question is about inheriting ONE of two classes. One OR the other. I have an external unchangeable DLL that provides me with two abstract ...
Daniel Möller's user avatar
7 votes
2 answers
186 views

C++ class with multiple inheritance and covariant return types

I am trying to understand a compile error from the latest version of VC++. The error occurs in a class that inherits from two base classes and includes a virtual function that overrides functions in ...
Bill Greene's user avatar
0 votes
1 answer
153 views

Subclass of tkinter's Toplevel class doesn't seem to inherit "tk" attribute

I'm writing a Python application using tkinter GUI. I created the TimestampWindow class which should be one of my Windows and made it extend the Toplevel class of tkinter's library and Window, a ...
ela's user avatar
  • 401
2 votes
1 answer
146 views

Methods with same names in multiple inteheritance in C++ [duplicate]

I have a program #include <iostream> struct A { virtual char f() = 0; }; struct B { virtual char f() = 0; }; struct Derived : A, B { public: char A::f() override { return CA; } ...
Dmitry's user avatar
  • 154
3 votes
2 answers
101 views

Template resolution in method with a class template parameter is not working when using multiple inheritance in base class. Why? How?

Consider the following code: template<typename T> struct Ambiguous_C { void func(T); }; struct Ambiguous_F { template<typename T> void func(T); }; struct Conflicted_F : ...
Rddvldny's user avatar
2 votes
0 answers
87 views

Ruby Inheritance Chain: Reusability [closed]

How would be possible to re-use a full inheritance chain by changing configuration parameters? (i.e. constants) The base inheritance chain So let's say we have this inheritance chain C < B < A ...
rellampec's user avatar
  • 781
0 votes
1 answer
85 views

How to "collect" all items associated with a chain of superclasses?

Problem Let's say I have a hierarchy of classes where each class has an associated list of class-specific items, e.g. class Thing: Items = ['Exist'] class Being(Thing): Items = ['Live', 'Die']...
Alex Sotka's user avatar
0 votes
2 answers
99 views

Inheriting a Class during Construction/Initialization in Python?

For a minimalist example, say I have three classes: class A(): def method(self): print('A') self._method() def _method(self): pass class B(A): def _method(self): ...
HellSaint's user avatar
  • 121
1 vote
1 answer
79 views

How to fix inconsistent method resolution order when deriving from ctypes.Structure and Mapping

Given the following Python code: import ctypes from collections.abc import Mapping class StructureMeta(type(ctypes.Structure), type(Mapping)): pass class Structure(ctypes.Structure, Mapping, ...
Markus's user avatar
  • 3,397
0 votes
3 answers
114 views

Python initialization with multiple inheritance

I have the following class hierarchy. The goal is for the calling code to choose either a base Foo object or a Foobar object that also provides the additional Bar functionality. class Foo: def ...
Ilya's user avatar
  • 645
-1 votes
1 answer
66 views

How is super() able to (apparently) resolve to, and call, multiple methods?

I'm working on some Python code that seems like it'll be a good fit for multiple inheritance, and I'm reading about multiple inheritance and super() to make sure I correctly understand how they work. ...
Lux's user avatar
  • 353
0 votes
1 answer
219 views

How to fix order of inherited subclasses in Python Dataclass

I am trying to create a Dataclass for a Latitude&Longitude using inherited subclasses of Latitude and Longitude. But the order of the inherited subclasses is incorrect. from dataclasses import ...
akarich73's user avatar
0 votes
0 answers
71 views

Calling base class from 2 levels of derived class [duplicate]

I wish to call an overridden base class function from 2 or 3 levels down. For example public class Level1 { public virtual void Encrypt(byte[] plain) { Console.WriteLine("level1&...
cup's user avatar
  • 8,528
3 votes
1 answer
84 views

str() of a dict subclass does not return "{}" per the MRO

With a class that inherits from dict, why does str() not use dict.__str__ when dict is earlier in the MRO of the class? Python 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] on linux Type "...
Tniagcpm's user avatar
1 vote
1 answer
65 views

How to solve this multiple inheritance properly (nice solution)

I want to call update for each derived object without a loop, this is the code that produces the loop from method "update()". How to solve it the right way? #include <iostream> class ...
extreme001's user avatar
2 votes
2 answers
58 views

Class works with SuperClass.__init__() but not with super().__init__()

I have the class structure below. Just ignore the minor issues such as mismatching variable names, this is not the issue here, I'll explain what is in a moment. class A: def __init__(self, a, b, c,...
a82fd72deb's user avatar
0 votes
1 answer
67 views

Error: The request matched multiple endpoints, when I inherit from BaseController

I created a BaseController to control access to methods of all child controllers, and it is in the following code: public class BaseController : Controller { protected readonly ...
Yousif Al-Zoubi's user avatar
0 votes
1 answer
68 views

Reuse inheritance tree of one out of multiple classes in Python

I have 2 classes each implementing a specific behavior and using parent classes. Now I have a new class that needs to use either behavior but which one can only be determined during/after construction....
Flamefire's user avatar
  • 5,927
2 votes
3 answers
582 views

Why does TS allow interface multiple inheritance?

I'm learning TypeScript about extending the interface. I unintentionally recognized that TypeScript allows extending interface from multiple classes. That made me surprised and I have researched a lot ...
LeoPkm2-1's user avatar
  • 199
1 vote
2 answers
100 views

C++ Multiple Inheritance: Implementing interfaces with overlapping virtual functions

I'm trying to design a class hierarchy in C++ where I have a base interface FooInterface with a pure virtual function foo(), and another interface FooBarInterface that should extend FooInterface and ...
HiroIshida's user avatar
  • 1,603
3 votes
1 answer
353 views

Creating a metaclass that inherits from ABCMeta and QObject

I am building an app in PySide6 that will involve dynamic loading of plugins. To facilitate this, I am using ABCMeta to define a custom metaclass for the plugin interface, and I would like this custom ...
KBriggs's user avatar
  • 1,488
1 vote
2 answers
45 views

Does multiple data processing violate the principle of interface separation?

I have the code. @startuml interface DbReader{ {abstract} read() } interface DbWriter{ {abstract} write(obj) } class DbConcrete { read() write(obj) } DbConcrete .up.|> DbReader DbConcrete .up.|...
Alexander Rakhmaev's user avatar
0 votes
2 answers
102 views

multiple inheritance without defining a class [duplicate]

I'm not sure that's possible, and I'm wondering if that's the way to go, or if there exists a better way of doing that. I'll create a toy example to expose what I'm looking for. Suppose I have people ...
user avatar
-1 votes
2 answers
96 views

The operators for my derived class do not work as intended

I made this code that has 4 classes. The SpecialCharacter class has 2 bases, Hero and Enemy, both of which have Person as their base class. #include <iostream> class Person { private: char* ...
Digits's user avatar
  • 23
2 votes
1 answer
107 views

Override function with variadic template inheritance

I have a class that inherits from 2 sets of base classes, according to variadic template arguments. One of those sets defines a virtual function. I want to do something like this but I'm not sure how ...
Leonardo Faria's user avatar
1 vote
1 answer
503 views

Python Multiple Inheritance generates "TypeError: got multiple values for keyword argument"

I'm running into a problem using multiple inheritance in Python. In my code, Child class A inherits from two Parent classes, B and C, both abstract base classes. Each of the Parent classes, B and C, ...
Overtoad's user avatar
1 vote
1 answer
135 views

How should I write Google-Truth Subjects for an object heirarchy that uses interfaces for multiple-inheritance?

The situation I'm writing tests for a personal project (in Java17 using JUnit5/Jupiter and Google Truth ) where I use the multiple-inheritance of interfaces to define classes. For example: Example ...
GeenDutchman's user avatar
1 vote
0 answers
123 views

How to properly inherit from multiple interfaces which declare signals and slots in Qt 6

I want to have two different interface classes that declare signals and pure virtual slots, and have a implementation class that implements both of them and thus inherits their individual signals and ...
Punitto Moe's user avatar
0 votes
1 answer
40 views

How can I create an adapter that can adapt between two different data machine classes

A class that stores and handles access to some machine of type A: class DataMachineA: def __init__(self): # some dummy data self.data = {"type": ["A", "A&...
amalelwatta's user avatar
1 vote
3 answers
86 views

C++ multiple inheritance- class method running twice

I have an exercise to practice multiple inheritance and polymorphism and something is not going well. The exercise includes 4 classes I need to build: Creature char * name int age int numOfOffsprings ...
Reef Kenig's user avatar
2 votes
1 answer
131 views

Why is there a difference between an operator and the corresponding member function?

Why is there a difference between the operator call and the corresponding member function call with Clang 17.0.1? Shouldn't they behave the same way? #include <iostream> struct A { void ...
user avatar
3 votes
2 answers
91 views

C++ Runtime polymorphism calling unexpected override when multiple classes are inherited

I am trying to create a GUI system with C++11 where, perhaps like Godot, every "node" has a very specific purpose such as grouping other nodes, drawing a rectangle, or detecting when a ...
CreeperCrafter979's user avatar
0 votes
1 answer
42 views

Multiple inheritance: how to correctly override a method? The complementary of the complementary of an object

TL; DR I'm trying to implement the complementary of the complementary of a spatial region The current solution works with a huge side effect The solution is based on multiple inheritance. Which doesn'...
tiago.seq's user avatar
5 votes
1 answer
233 views

Is it legal to zero empty C++ classes in the constructor and inherit from them?

It is not very rare to find a library that zeros its objects in the constructors using memset. And sometimes it happens to empty classes as well. Is it safe, especially when one inherits such classes? ...
Fedor's user avatar
  • 24.7k
1 vote
0 answers
73 views

Cannot implement multiple inheritance with QObject

Code snippet: from PyQt5.QtWidgets import QApplication from PyQt5.QtCore import QObject import sys class ParentA: def __init__(self, x, y): self.b = x + y class Child(QObject, ParentA): ...
hamo's user avatar
  • 25
1 vote
1 answer
73 views

Name hiding when multi-inherited

According to https://www.ibm.com/docs/en/i/7.5?topic=only-name-hiding, the assignment x = 0 in the following code is not ambiguous, because the declaration B::x has hidden A::x. struct A { int x; };...
xiaokaoy's user avatar
  • 1,733
0 votes
2 answers
89 views

C++ multiple inheritance: avoiding reimplementation of a pure virtual function if the same function is already implemented in one of the parents

I have this class hierarchy in C++: class ISegmentReader { public: virtual void readCacheFromDb() = 0; //... }; class ISegmentManager: public ISegmentReader { //readCacheFromDb not ...
user129186's user avatar
  • 1,268
0 votes
2 answers
101 views

mutiple inheritance: use __init__ method of two superclasses

I want to make multiple inheritance, making a subclass inherit from two different super classes. This subclass should have an __init__ method in which the __init__ methods of the super classes are ...
Arkeor's user avatar
  • 77
2 votes
1 answer
94 views

Unexpected method call order in Python multiple inheritance

I have a child class named USA and it has two parent classes, A and B. Both parents have a method named change_to_4 and in B.__init__ I call the method, but instead of using the method that I defined ...
Ali Rashidi's user avatar
0 votes
1 answer
126 views

Multiple inheritance going from one Base Class to another [duplicate]

Assunme I have some abstract class A. I want to cast into some other class B only if the dynamic type of A is a class that also inherits from B. Is there a good way to do this that doesn't involve ...
ILutRf7's user avatar
  • 71
0 votes
0 answers
63 views

Selective Typedefs Inheritance at Compile Time

Imagine I have a big list of typedefs that I don't want to repeat for all classes, and I create a base class: template<class Derived> class TypesDefs { using ptr = std::shared_ptr<Derived&...
SpeakX's user avatar
  • 427
0 votes
0 answers
47 views

Unable to use super() with multiple inheritance in Python [duplicate]

as part of a practice of our Python knowledge, we are required to create a child class that inherits from A,B,C, to produce the output "The Name is Elzero". While I managed to do it using ...
ProgrammingLearner2023's user avatar
0 votes
0 answers
117 views

Serializing multiple inheritance models in Django REST Framework

I have this model structure: class Main (models.Model): name=models.Charfield(max_length=50) ... class Category (Main): type=models.Charfield(max_length=50) ... class SubCategory1(...
javistro's user avatar
0 votes
1 answer
70 views

Is there any reason to do to multiple inheritance with object?

While reviewing some code, it has a structure like class Bar(Foo, object): Which seems like it could easily be written instead as class Bar(Foo): The functionally appears at least the same the ...
ti7's user avatar
  • 19.8k

1
2 3 4 5
56