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
31
votes
3 answers

How to resolve "pure virtual method called"

I understand why this is happening, but I'm stuck trying to resolve it...here is what my code is doing when the error is generated (thus, leading to a crash) when my program exits... pure virtual method called SomeClass::~SomeClass() { …
user869525
  • 769
  • 2
  • 12
  • 21
24
votes
2 answers

How do derived class constructors work in python?

I have the following base class: class NeuralNetworkBase: def __init__(self, numberOfInputs, numberOfHiddenNeurons, numberOfOutputs): self.inputLayer = numpy.zeros(shape = (numberOfInputs)) self.hiddenLayer = numpy.zeros(shape =…
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
22
votes
7 answers

Derived and base class, can I set the base explicitly?

public class SuperCar: Car { public bool SuperWheels { get {return true; } } } public class Car { public bool HasSteeringWheel { get {return true;} } } How can I set the base class for the derived Supercar? For example, I want to simply…
Watson
  • 1,385
  • 1
  • 15
  • 36
22
votes
5 answers

How do I use an XmlSerializer to deserialize an object that might be of a base or derived class without knowing the type beforehand?

In C#, how do I use an XmlSerializer to deserialize an object that might be of a base class, or of any of several derived classes without knowing the type beforehand? All of my derived classes add additional data members. I've made a simple GUI that…
8bitcartridge
  • 1,629
  • 6
  • 25
  • 38
22
votes
4 answers

Virtual Table C++

I read a lot of people writing "a virtual table exists for a class that has a virtual function declared in it". My question is, does a vtable exists only for a class that has a virtual function or does it also exist for classes derived from that…
Frank Q.
  • 6,001
  • 11
  • 47
  • 62
22
votes
2 answers

How do I call a derived class method from the base class?

I have read several similar questions about this but none seem to solve the problem I am facing. The typical answer is to cast as the derived class but I cannot since I do not know the derived class type. Here is my example: class WireLessDevice {…
CramerTV
  • 1,376
  • 1
  • 16
  • 29
21
votes
9 answers

C#: How do I call a static method of a base class from a static method of a derived class?

In C#, I have base class Product and derived class Widget. Product contains a static method MyMethod(). I want to call static method Product.MyMethod() from static method Widget.MyMethod(). I can't use the base keyword, because that only works with…
MindModel
  • 822
  • 1
  • 10
  • 22
20
votes
4 answers

Execute a derived constructor before the base constructor in C#

My problem here is that I would like to pass an object to a derived class, but it must be done before the base class constructor, since the base class will immediately call the derived class's Start() method that uses the object. Here's an excerpt…
James
  • 659
  • 1
  • 5
  • 15
18
votes
4 answers

Not calling base class constructor from derived class

Say I have a base class: class baseClass { public: baseClass() { }; }; And a derived class: class derClass : public baseClass { public: derClass() { }; }; When I create an instance of derClass the constructor of…
Brad
  • 10,015
  • 17
  • 54
  • 77
17
votes
1 answer

Match a class by parameter type in a c++ template-generated class hierarchy

Intro I am working on a custom memory allocator and need to add some bookkeeping info to the header of each allocated chunk. There are several different chunk types and the bookkeeping info differs as well. For instance, for chunks shared between…
Aleksey Demakov
  • 426
  • 4
  • 7
17
votes
7 answers

How to Get Base Class Instance from a Derived Class

I don't know if this is possible, but I am trying to get the Base Class instance from a Derived Class. In C#, I can use the base keyword to access properties and methods of the Base Class (of course), but I want to use base itself. Attempting to do…
OneSource
  • 519
  • 3
  • 8
  • 23
16
votes
5 answers

Why is 'virtual' optional for overridden methods in derived classes?

When a method is declared as virtual in a class, its overrides in derived classes are automatically considered virtual as well, and the C++ language makes this keyword virtual optional in this case: class Base { virtual void f(); }; class…
squelart
  • 11,261
  • 3
  • 39
  • 43
15
votes
3 answers

How to pass List when param type is List?

How can i pass a list which is a list of DerivedObjects where the Method is expecting a list of BaseObjects. I am converting the list .ToList() and am wondering if there is a better way. My second problem is the syntax is incorrect. I am…
Valamas
  • 24,169
  • 25
  • 107
  • 177
13
votes
3 answers

C++ template with 'const'

Consider the following template class: template class Function { public: virtual float eval( const T &x, const T &y ) = 0; }; Since the 'eval' function should not modify the value of the two inputs 'x' and 'y', I put them as…
13
votes
2 answers

std::bind()-ing a base protected member function from a derived class's member function

I want to bind() to my base class's version of a function from the derived class. The function is marked protected in the base. When I do so, the code compiles happily in Clang (Apple LLVM Compiler 4.1) but gives an error in both g++ 4.7.2 and in…
OldPeculier
  • 11,049
  • 13
  • 50
  • 76
1
2
3
79 80