Questions tagged [derived-class]

In Object Oriented languages, derived class can inherit properties and/or member functions from a base class, also called super class. cf inheritance and polymorphism.

In Object Oriented languages, derived class can inherit properties and/or member functions from a base class, also called super class. cf inheritance and polymorphism.

1192 questions
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
2 answers

Maybe my understanding of [class.access]/7 isn't correct, but

From [class.access]/7 we have the following sentence: Similarly, the use of A::B as a base-specifier is well-formed because D is derived from A, so checking of base-specifiers must be deferred until the entire base-specifier-list has been…
Belloc
  • 6,318
  • 3
  • 22
  • 52
10
votes
2 answers

How does the derived class destructor get invoked being private in the following program?

#include class base { public: virtual ~base(){std::cout << "base\n";} }; class derived : public base { private: ~derived(){std::cout << "derived\n";} /* destructor is private */ }; int main() { base *pt= new…
Kaustav Ray
  • 744
  • 6
  • 20
10
votes
2 answers

Python print isn't using __repr__, __unicode__ or __str__ for unicode subclass?

Python print isn't using __repr__, __unicode__ or __str__ for my unicode subclass when printing. Any clues as to what I am doing wrong? Here is my code: Using Python 2.5.2 (r252:60911, Oct 13 2009, 14:11:59) >>> class MyUni(unicode): ... def…
Rafe
  • 1,937
  • 22
  • 31
10
votes
1 answer

Effects of a const base class

What is the actual effect of the following construct: class Base { /* ... */ }; template class Derived : public T { /* ... */ }; int main() { Derived d; // ... } Does the Derived class only have access to the…
phlipsy
  • 2,899
  • 1
  • 21
  • 37
10
votes
8 answers

What is the difference between a child of a parent class and the derived of a base class in VB.NET or C#?

After asking the question Call a method that requires a derived class instance typed as base class in VB.NET or C# on Stack Overflow, I was informed that I had used the wrong terms when asking the question. I had used "parent" and "child" where I…
Gravitate
  • 2,885
  • 2
  • 21
  • 37
10
votes
3 answers

How to partially specialize a class template for all derived types?

I want to partially specialize an existing template that I cannot change (std::tr1::hash) for a base class and all derived classes. The reason is that I'm using the curiously-recurring template pattern for polymorphism, and the hash function is…
Doug
  • 8,780
  • 2
  • 27
  • 37
9
votes
6 answers

C++ Call derived function from base class instance

I am fairly new to C++, but i have ran into an issue which i cannot seem to resolve. I will use cars to illustrate the problem, just to make things easier. Okay so lets say that i have a base class Car, and i have different brands that are…
Dan
  • 101
  • 1
  • 4
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
2 answers

What is the difference between "extends" and "implements" in java with respect to performance and memory,etc

What is the difference between extends and implements in java with respect to performance and memory,etc. For example take the following scenarios, 1) public interface PrintResult { public final int NO_ERROR=0; public final int SUCCESS=1; …
SIVAKUMAR.J
  • 4,258
  • 9
  • 45
  • 80
9
votes
7 answers

Can a base-class method return this, even in a derived class?

I'd like to be able to have a method in a C# base class, callable on objects of several derived classes, that returns the object itself, and have the CLR know what type the object really is - i.e., the appropriate derived type. Can someone suggest…
Ross Patterson
  • 9,527
  • 33
  • 48
9
votes
10 answers

When should a virtual method be pure?

I have found some code that I am working on, and was wondering what the best design implementation is. If a base class defines a method as virtual, but implements an empty body as well, thus not requiring the derived classes to implement a body,…
Ian Vaughan
  • 20,211
  • 13
  • 59
  • 79
9
votes
1 answer

C# - calling base version of overridden method

Suppose there is base class A and derived class B. Class A has two functions: fun1() and fun2(), where fun1() calls fun2(). Class B overrides fun1() and fun2(), and again fun1() calls fun2(). However, I'd like to call base.fun1() in overriden…
Maras
  • 982
  • 9
  • 15
9
votes
1 answer

Derive Ord with Quantified Constraints (forall a. Ord a => Ord (f a))

With quantified constraints I can derive Eq (A f) just fine? However, when I try to derive Ord (A f) it fails. I do not understand how to use quantified constraints when the constraint class has a superclass. How do I derive Ord (A f) and other…
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