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

I don't understand inheritance with base classes

My understanding of inheritance is pretty basic. I want to create a base class, which implements IDisposable and then let other classes with functionality inherit from that base class, so that they share a base type. It would allow me to put every…
Rakku
  • 55
  • 4
4
votes
5 answers

Inheritance base class reference C#

class Base { //... public int i = 5; } class Drifted : Base { //... public int b = 10; } Base ObjectOrReference = new Drifted(); So Base ObjectOrReference;is reference to the base type. When we write Base…
Nikita
  • 315
  • 1
  • 7
  • 14
4
votes
1 answer

Can I detect which types, when used as a base class, potentially overlap their derived class

Consider the following class: class intchar { int x; char y; }; It has size 8 on all major compilers on x86. Consider now the a derived class: struct derived : intchar { char z; }; On gcc and clang for Linux1, this class also has size…
BeeOnRope
  • 60,350
  • 16
  • 207
  • 386
4
votes
2 answers

C# Use base class property value in a derived class property override

My class structure is as follows: public class Animal { private int _animalId; public virtual int AnimalId { get { return _animalId; } } } public class Dog : Animal { public override int AnimalId { get …
full-stack
  • 553
  • 5
  • 20
4
votes
5 answers

C++ replace base class in derived class

I believe I'm thinking about this "badly" (non-C++'y). Here's what I'm trying to do class AA { public: AA(const char* name, unsigned short number); int Write(int x); ... } class BB: public AA { public: …
Dweeberly
  • 4,668
  • 2
  • 22
  • 41
4
votes
4 answers

How to use dynamic_cast in if statement

So I've got a simple task to do. There are 3 classes derived from one base class. They're quite simple and will be provided below. What I need to do is create a new class called PolymorphicAnimal, that'll be able to behave just as any other animal…
Melvin Brooks
  • 73
  • 1
  • 6
4
votes
3 answers

Generating member types for containers

When I define my own containers, I have to provide a dozen of member types, for example: typedef T& reference; typedef const T& const_reference; typedef T* iterator; typedef const T* const_iterator; typedef std::size_t…
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
4
votes
4 answers

Remove field from a subclass of base abstract class Django

I am creating an application which needs a commenting system. I decided to use the comment app of Django, but needed to alter it a bit. First I do not want the user's email id to be mandatory and next I need an option to attach a file with the…
satran
  • 1,222
  • 4
  • 16
  • 27
4
votes
2 answers

FindObjectOfType returning null

The issue I am having is with a dropped item i pick up adding ammo to a gun. Built a Gun class with all the methods and variables. Built a Rifle class derived from the Gun class The Rifle works perfect No Issues I now am adding a "PickUp"…
4
votes
3 answers

ASP.NET MVC: Ignore custom attribute in a base controller class

I have a number of Controllers in my project that all inherit from a controller I've named BaseController. I wrote a custom attribute that I applied to the entire BaseController class, so that each time an action runs in any of my controllers, that…
Matt
  • 23,363
  • 39
  • 111
  • 152
4
votes
1 answer

Why is my instance variable acting like a class variable in AHK?

Here is the basic structure of what I am trying to do: OutputDebug % "~~~~~ START ~~~~~" tempA := new ClassA() tempB := new ClassB() tempC := new ClassC() tempA := 0 tempB := 0 tempC := 0 OutputDebug % "~~~~~ END ~~~~~" return class Base { …
Paige DePol
  • 1,121
  • 1
  • 9
  • 23
4
votes
1 answer

Template inheritance and a base member variable

I get a weird error when trying to use template inheritance. This is my code: template class A { public: int a {2}; A(){}; }; template class B : public A { public: B(): A() {}; void test(){ std::cout…
Jiří Lechner
  • 750
  • 6
  • 19
4
votes
3 answers

Can a grails controller extend from a base class? How to make it so grails doesn't blow up?

I wrote a base class to help build my controllers more quickly and to remove duplication. It provides some helper methods, default actions and some meta programming to make these things easier to build. One of those methods in the base class is like…
egervari
  • 22,372
  • 32
  • 121
  • 175
4
votes
1 answer

What is happening when a Constructor uses 1 argument, but base keyword uses 2 arguments

I have this bit of code and it will demonstrate a Liskov substitution, but I'm confused what the base keyword is doing with 2 arguments. Can someone explain? class Rectangle { public Rectangle(int width, int height) { Width = width; …
christopher clark
  • 2,026
  • 5
  • 28
  • 47
4
votes
1 answer

Can't call base class constructor with brace initialization intellisense error

I just encountered the following problem: #include "stdafx.h" #include #include class transaction{ protected: transaction(const std::string& log) { printLog(log); } private: void printLog(const std::string& log) const {…