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
10
votes
2 answers

Detect common base class

Suppose one has a class hierarchy, without multiple inheritance: struct TOP{}; struct L : TOP{}; struct R : TOP{}; struct LL : L{}; struct LR : L{}; struct RL : R{}; struct RR : R{}; Is it possible to write a metafunction that will return the type…
alfC
  • 14,261
  • 4
  • 67
  • 118
10
votes
3 answers

Is it possible a class to inherit only some(not all) base class members?

Is there a way that a derived class could inherit only a few of all the base class members..in C#? If such maneuver is possible, please provide some example code.
CSharp4eto
  • 147
  • 2
  • 6
10
votes
1 answer

Angular 2 Base Class Output EventEmitter doesn't get raised or handled

Very simple base class Closer import {EventEmitter, Output} from 'angular2/core'; export class Closer { @Output() closed: EventEmitter = new EventEmitter(); constructor() {} close() { this.closed.emit({}); } } If I extends…
jkyoutsey
  • 1,969
  • 2
  • 20
  • 31
10
votes
4 answers

What is the difference between a simple base class and abstract class?

I was doing a kind of R&D and am confused with the concept of an abstract class. What I know about an abstract class is that it may contain concrete methods, and it may contain virtual methods. It may or may not contain an abstract method, and it…
peter
  • 8,158
  • 21
  • 66
  • 119
10
votes
2 answers

Generic type constraint of new() and an abstract base class

Here we have a simple class herarchy, and use of generics with a type constraint of new() public abstract class Base { } public class Derived : Base { } public class TestClass { private void DoSomething(T arg) where T : new() { } …
Richard Ev
  • 52,939
  • 59
  • 191
  • 278
9
votes
2 answers

How do we call a virtual method from another method in the base class even when the current instance is of a derived-class?

How do we call a virtual method from another method in the base class even when the current instance is of a derived-class? I know we can call Method2 in the Base class from a method in the Derived class by using base.Method2() but what I want to do…
Setyo N
  • 1,953
  • 2
  • 26
  • 28
9
votes
4 answers

Raise Base Class Events in Derived Classes C#

I have a base class DockedToolWindow : Form, and many classes that derive from DockedToolWindow. I have a container class that holds and assigns events to DockedToolWindow objects, however I want to invoke the events from the child class. I actually…
Game_Overture
  • 1,578
  • 3
  • 22
  • 34
9
votes
4 answers

need to call the base destructor method from a derived class in c++?

Please consider the following: class base{ base(); ~base(); }: class derived : public base{ }; Does a base class destructor get automatically invoked when a derived object is destructed when the derived class has no destructor…
Heisenbug
  • 38,762
  • 28
  • 132
  • 190
9
votes
2 answers

C++: Protected Class Constructor

If a class is always going to be inherited, does it make sense to make the constructor protected? class Base { protected: Base(); }; class Child : protected Base { public: Child() : Base(); }; Thanks.
user542687
9
votes
1 answer

Base template class data members are not visible in derived template class?

Consider the following C++ code, template struct A { bool usable_; }; template struct B : A< B > { void foo() { usable_ = false; } }; struct C : B { void foo() { …
user511274
  • 503
  • 4
  • 8
9
votes
2 answers

C++: inexplicable "pure virtual function call" error

I am having a bit of a struggle with Microsoft Visual C++ 2015 and was able to replicate the issue with a small program. Given the following classes: class BaseClass { public: BaseClass() : mValue( 0 ) , mDirty( true ) {} …
Paul Houx
  • 1,984
  • 1
  • 14
  • 16
9
votes
2 answers

Can a Base Class Method return the type of the derived class?

Based on the other posts I have read, it seems that this may not be possible, but I thought I would post what I am trying to do and see if anyone knows of a solution. I am trying to add a "Clone()" method to classes generated from a Telerik Open…
Gary O. Stenstrom
  • 2,284
  • 9
  • 38
  • 59
9
votes
3 answers

Pass this to base constructor

I am trying to implement good design patterns for a program I am writing. I have a class structure like this. abstract class SomeBase { public SomeObject obj { get; protected set; } protected SomeBase(SomeObject x) { obj…
guitar80
  • 716
  • 6
  • 19
9
votes
3 answers

Use selenium webdriver as a baseclass python

I searched for a while for this one and was surprised i couldn't find anything, maybe because it's simple. I've been programming in python for about 3 months doing automated testing with selenium webdriver. I was thinking it would be convenient to…
ReckerDan
  • 326
  • 2
  • 8
8
votes
3 answers

Adding virtual removes the error : type 'base' is not a direct base of derived class

Conside the following sample code below: #include using namespace std; class base { public: base() { cout << "ctor in base class\n"; } }; class derived1 : public base { public: derived1() { …
nitin_cherian
  • 6,405
  • 21
  • 76
  • 127