Questions tagged [base-class]

In Object Oriented Programming, a base class is one from which other classes inherit. For example, a child-class `Male` and another child-class `Female` may both inherit from the base-class `Human`.

In Object Oriented Programming, a base class is one from which other classes inherit. For example, a child-class Male and another child-class Female may both inherit from the base-class Human. As a result of such an inheritance, each of them will have at least all the attributes and methods of the class Human and perhaps a few others.

678 questions
8
votes
6 answers

Can you override private functions defined in a base class?

I believe, a derived class can override only those functions which it inherited from the base class. Is my understanding correct.? That is if base class has a public member function say, func, then the derived class can override the member function…
nitin_cherian
  • 6,405
  • 21
  • 76
  • 127
8
votes
5 answers

Constructor and Destructor Inheritance

I believe Constructors and Destructors in base class cannot be inherited by derived classes of the base class. Is my understanding correct.
nitin_cherian
  • 6,405
  • 21
  • 76
  • 127
8
votes
1 answer

Javascript prototype extend base-class unable to access base-class properties/methods from prototype class

I have created a javascript class TkpSlider being inspired from this w3schools page. (JSFiddle) var TkpSlider = function (args) { args= args|| {}; }; var mainSwiper = new TkpSlider(); I have extended this to add some swipe ability being…
Ardeus
  • 1,921
  • 3
  • 17
  • 26
8
votes
4 answers

kotlin, how to simplify passing parameters to base class constructor?

We have a package that we are looking to convert to kotlin from python in order to then be able to migrate systems using that package. Within the package there are a set of classes that are all variants, or 'flavours' of a common base class. Most of…
innov8
  • 2,093
  • 2
  • 24
  • 31
8
votes
2 answers

Python number base class OR how to determine a value is a number

Python seems to lacks a base class for "all numbers", e. g. int, float, complex, long (in Python2). This is unfortunate and a bit inconvenient to me. I'm writing a function for matching data types onto each other (a tree matching / searching…
Alfe
  • 56,346
  • 20
  • 107
  • 159
8
votes
1 answer

What are the disadvantages of having one base class for all exceptions?

I'm doing the exercises from Stroustrup's C++ Programming Language 4th Edition. One of the tasks is formulated like this: Consider using a class Exception as the base of all classes used as exceptions. What should it look like? How should it be…
sigil
  • 815
  • 8
  • 16
8
votes
2 answers

Why there is a restriction for a base-class subobject?

3.9/2: For any object (other than a base-class subobject) of trivially copyable type T, whether or not the object holds a valid value of type T, the underlying bytes (1.7) making up the object can be copied into an array of char or unsigned…
user2953119
8
votes
3 answers

Guarantees on address of baseclass in C++?

In C struct's, I'm guaranteed that: struct Foo { ... }; struct Bar { Foo foo; ... } Bar bar; assert(&bar == &(bar.foo)); Now, in C++, if I have: class Foo { ... }; class Bar: public Foo, public Other crap ... { ... } Bar bar; assert(&bar ==…
anon
  • 41,035
  • 53
  • 197
  • 293
8
votes
2 answers

Inconsistent accessibility: base class is less accessible than child class

I am reading book "C# 4.0 in a nutshell" by Joseph Albabari and Ben Albabari. From there I find a topic restrictions on access modifiers. Page 91, Topic "Restrictions on Access Modifiers". Quoting from the book. The compiler prevents any…
fhnaseer
  • 7,159
  • 16
  • 60
  • 112
7
votes
2 answers

Entity Framework 4.1 Code First: Get all Entities with a specific base class

I have a DbContext with set up different DbSets with all types that derive from the same base class: public class Foo : Entity { } public class Bar : Entity { } MyDbContext : DbContext { public DbSet Foos { get; set; } public DbSet
7
votes
3 answers

Pointer to member question

$4.11/2 states - An rvalue of type “pointer to member of B of type cv T,” where B is a class type, can be converted to an rvalue of type “pointer to member of D of type cv T,” where D is a derived class (clause 10) of B. If B is an …
Chubsdad
  • 24,777
  • 4
  • 73
  • 129
7
votes
3 answers

Erroneous private base class inaccessible?

Compiling this code using g++ 4.2.1: struct S { }; template struct ST { }; template class ref_count : private BaseType { }; template class rep_base : public RefCountType { }; class wrap_rep :…
Paul J. Lucas
  • 6,895
  • 6
  • 44
  • 88
7
votes
3 answers

Can a derived class be made uncopyable by declaring copy constructor/operator private in base class?

I thought in theory the answer to this question was yes. However, in practice, my compiler (VS2010) does not seem to complain in the following situation: I have an abstract base class providing some common interface (yet having no data members) and…
mr_T
  • 2,571
  • 3
  • 22
  • 39
7
votes
5 answers

How to make a subclass constructor based on a parent class instance?

I have an Item and a subclass AdvancedItem (all made of value-types if that matters): public Item { public string A; public bool B; public char C; ...// 20 fields } public AdvancedItem : Item { public string Z; } It's easy to…
Cœur
  • 37,241
  • 25
  • 195
  • 267
7
votes
1 answer

Injecting dependencies into both the base class and subclass with IoC?

If I have a base class with services injected via constructor dependencies: Is it possible to declare the constructor of the subclass without using : base (params)? public MyBaseClass { private IServiceA _serviceA; private IServiceB…
JK.
  • 21,477
  • 35
  • 135
  • 214