Skip to main content
The 2024 Developer Survey results are live! See the results

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.

1 vote
0 answers
35 views

PHP - Issue when adding a return type declaration for a parent class [closed]

I have currently have the following classes: class Textarea Extends Field {} class Field {} I'm trying to declare a return type for the following function public function field(string $field): Field ...
Jackatron's user avatar
0 votes
3 answers
28 views

Overriding a variable assigned to an evaluated method in the parent class using a child class

I am new to object oriented programming. I have a parent class in whose constructor I have a variable (bmi in the below example) that requires a method (bod_mass_idx) of the same class to be evaluated ...
haricash's user avatar
1 vote
1 answer
42 views

Inheritance and Visibility in Swift

I'm confused about the content in the swift doc: Notice that the initializer for the EquilateralTriangle class has three different steps: Setting the value of properties that the subclass declares. ...
Chen Sam's user avatar
0 votes
1 answer
45 views

Error during inheritance from RazorPage<TModel>

I want to use localization in AspCore Razor Page. But, I am encountering the following errors: CS0108: 'Pages_Index.ViewData' hides inherited member 'RazorPage<IndexModel>.ViewData'. Use the new ...
moslem aslani's user avatar
1 vote
2 answers
57 views

How to add an ArrayList in a Superclass using Getters and Setters from a subclass

Here is the super class: public abstract class ImperialCluster implements Serializable,Clusterable { private static final long serialVersionUID = 1L; private String clusterType; ...
Tomas Gutierrez's user avatar
0 votes
1 answer
42 views

How would I reference a variable only in an inherited class?

So for a game I'm developing I'm using a inheritance based finite state system for enemy and boss AI. However I'm coming across a few issues with its implementation. The base state class is inherited ...
Glass Shard Games's user avatar
-1 votes
0 answers
29 views

how to call same method from parent and child class using child class object when the argument is same but the implementation is different in child [closed]

class Demo1{ void m1(int a) { System.out.println(a); } } class Demo2 extends Demo1{ void m1(int a) { System.out.println(a+a); } void m1(int ...
Disco Yapper's user avatar
-1 votes
1 answer
100 views

How can I avoid calling a static function (and call a base member function instead)?

I have a static instance (previously called singleton, but commenters were taking issue with that) of a class which derives from a base class. So far, so good. Derived has a static function fun, while ...
bers's user avatar
  • 5,397
0 votes
0 answers
53 views

Virtual Template Best Practice when Realization has small cardinality

I have the virtual template problem, i.e.: class Base{ public: // template<bool flag> virtual void eval()=0; // line A }; class Derived: public Base{ public: template<bool flag> ...
user23311233's user avatar
0 votes
1 answer
64 views

simulate method call mechanism of inheritance

I have a class hierarchy like this: public class Base { } public class Child1 : Base { } public class Child2 : Base { } I want to generate hashes for those classes. If I implemented these methods ...
Kjara's user avatar
  • 2,794
0 votes
1 answer
38 views

How to inherit (from a parent class) dataclass field introspection functionality?

I have a parent dataclass, and various other classes will then extend this parent dataclass. Let's call these dataclasses DCs. In the example code below, see ParentDC, and an example ChildDC: from ...
bzm3r's user avatar
  • 3,840
0 votes
0 answers
61 views

Get parent class in std::type_info map

I might have misunderstand how std::type_info and inheritance works, but when we have: class A { virtual void x() = 0; } class B : public A { virtual void y() = 0; } class C : public B { ...
Theofanis kouniakis's user avatar
-2 votes
0 answers
45 views

Error inheriting non pure virtual function from class that implement another class [closed]

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 ...
Danilo Namitala's user avatar
-2 votes
0 answers
57 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(...
Jeremy Friesner's user avatar
1 vote
1 answer
77 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 ...
Mike Land's user avatar
  • 480

15 30 50 per page
1
2 3 4 5
2849