Questions tagged [abstract-base-class]

In OOP (Object Oriented Programming), a base class that cannot be instantiated because some of its declared methods lack a definition, which is intended to be provided by derived classes. The term may have more specific or slightly different meaning according to the particular computer language involved.

109 questions
1
vote
1 answer

Pure virtual function in abstract class with return type of base/derived type

I wish to make each derived class of a base class to implement a function (in this case the postfix operator) which has the derived class' type as return type, as this: class A { virtual A operator++(int) =0; } class B : public A { B…
Parham
  • 3,157
  • 4
  • 31
  • 44
1
vote
3 answers

C# Xml-Serialization of abstract base type into derived type - which TypeName property definition wins?

My scenario: I have an object that I have defined with properties that are decorated with XmlElement tags and that have types that I have defined, some of which are typed as abstract that get set to respective derived types. I want to serialize this…
null
  • 153
  • 1
  • 3
  • 16
1
vote
4 answers

Pointer to base class lost in while loop, causing segfault. C++

This code uses a while loop to get user input and execute the appropriate command - I've reduced it to 2 commands for sake of brevity. The Oblock object is created correctly (command "O"), as is the pointer to the base class. It appears that the…
user3566909
1
vote
1 answer

Defining multiple derived Interface Members

I hope you can help me with the following problem. I am trying to create a flexible system of interfaces and hit a problem. This is the relevant code: // Interface 1 // this: virtual f_a // -> abstract struct I_A abstract { virtual void…
Beta Carotin
  • 1,659
  • 1
  • 10
  • 27
1
vote
3 answers

Unit testing passing arguments to base constructor

I have the following code: using System; using NUnit.Framework; using Rhino.Mocks; public class A { } public class B { } public interface IStatementExecutor …
drogon
  • 1,785
  • 3
  • 21
  • 34
0
votes
1 answer

Passing a web control reference to a User Control base class

I created several user controls - most containing a single web control (text box, drop down, radio button etc) - along with one or more validation controls. The point being to combine control and validation in a single user control. I created a…
mearle
  • 3
  • 2
0
votes
5 answers

STL List - Datatype as a pointer object

I'm having a problem using inheritance and the STL list library... Say, I have an abstract base class with two derived classes (where all comparison operators are defined). The list is declared as list items; I'm inserting a derived…
0
votes
1 answer

Can you force derived class from a bass class to define specific member variables in python?

If I have a class say: class BaseClassOnly(): def __init__(self): self._foo = None def do_stuff(self): print("doing stuff with foo" + self._foo) I want to force all classes derived from BaseClassOnly to provide a value for…
0
votes
1 answer

Inheriting from type and typing.Mapping: "TypeError: descriptor '__subclasses__' of 'type' object needs an argument"

I am trying to define a class that is supposed to simultaneously do two things: serve as the metaclass for a dataclass act like a mapping i.e., it will need to be derived from both type and typing.Mapping. Defining such a class itself works, but I…
0
votes
0 answers

What is the point of passing in params to an abstract base class in this manner?

I was trying to understand how the backtesting.py module is written and came across this code. class Strategy(metaclass=ABCMeta): """ A trading strategy base class. Extend this class and override methods …
0
votes
1 answer

how can vb.net make inherit class with selected variable from base calss

I need to make an inherited class from a base class with a selected variable. for example, if the base class have 3 variable name, age, marks but inherit class must have name and marks only how can we do it
0
votes
1 answer

Why default assignment operator is not called from assignment-from-base-class operator?

Implementing a derived class from abstract base class with assignment operator by using dynamic cast in base-to-derived assignment operator, I'd like to call derived-to-derived assignment operator. This works. #include using namespace…
Nick
  • 970
  • 10
  • 20
0
votes
1 answer

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(Base &&) = delete; Base &operator=(Base &&) = delete; …
Incredible
  • 3,495
  • 8
  • 49
  • 77
0
votes
1 answer

Use subclasses of abstract outer class in nested class

I want to use all subclasses of an abstract class in the nested config class of a pydantic class like this: def custom_json_loads(classes, ....): ##use classes here for json parsing class Outer(BaseModel, abc.ABC): name = "test" class…
Tabea
  • 39
  • 1
  • 7
0
votes
2 answers

Abstract base class or typing.Protocol for supporting __str__

Is there a builtin ABC for enforcing __str__ to be implemented in subclasses? Or a typing protocol? I want a function that only accepts classes with __str__ __hash__ and __eq__. I've found Hashable but not Stringable
Greedo
  • 4,967
  • 2
  • 30
  • 78