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
7
votes
1 answer

Virtual baseclass calls empty constructor in C++ (C++11)

Lets look at the following code: class A{ protected: int _val; public: A(){printf("calling A empty constructor\n");} A(int val):_val(val){printf("calling A constructor (%d)\n", val);} }; class B: virtual public A{ public: …
Wojciech Danilo
  • 11,573
  • 17
  • 66
  • 132
7
votes
5 answers

Why derived class function argument takes value of base class function argument?

I'm working on C++. Following is my code: #include using namespace std; class base { public: virtual void display(int a = 4) { cout << "base :: "<< a*a << endl; } }; class derived :…
BSalunke
  • 11,499
  • 8
  • 34
  • 68
6
votes
4 answers

when to use multiple class libraries?

When should I use multiple class libraries in .NET. I have a situation where I need to use the functionalities of Microsoft Office Object Model to check certain attributes of Microsoft Office files. Should I use different class libraries to process…
logeeks
  • 4,849
  • 15
  • 62
  • 93
6
votes
2 answers

copy & swap in base and derived class

I recently read about copy & swap and am now trying to implement the ctors in a base and derived class. I have the four constructors in both my base and derived class, however I am unsure how to implement the assignment operator of the derived…
gartenriese
  • 4,131
  • 6
  • 36
  • 60
6
votes
1 answer

constexpr address of base class

Using clang 3.4 (trunk), is there any way to calculate the displacement of a base class with a constant expression? struct A { int a; }; struct B { int b; }; struct C: A, B {}; // cannot access base class of null pointer: constexpr auto…
jdavidls
  • 348
  • 1
  • 5
6
votes
3 answers

Force derived class to call base function

If I derive a class from another one and overwrite a function, I can call the base function by calling Base::myFunction() inside the implementation of myFunc in the derived class. However- is there a way to define in my Base class that the base…
Mat
  • 11,263
  • 10
  • 45
  • 48
6
votes
2 answers

base.Method() with multiple levels of inheritance not being called?

I've searched and not been able to find any solution to my problem. My scenario is very simple: public class A { public virtual void MethodOne() { Console.log( "A" ); } } public class B : A { public override void…
helios
  • 87
  • 1
  • 1
  • 3
6
votes
4 answers

Derived Class Constructor Calls

If I have a base class: class Base{ ... }; and a derived class class Derived : public Base{ ... } does this derived class always call the default constructor of the base class? i.e. the constructor that takes no parameters? For example If I…
kjh
  • 3,407
  • 8
  • 42
  • 79
6
votes
2 answers

override List with List

I have base classes like this: public class Scene { public IList Models {get; set;} } public class SceneModel { } and derived classes like this: public class WorldScene : Scene { public override IList Models {get;…
kaykayman
  • 373
  • 2
  • 13
6
votes
2 answers

Invocation of SUPER::new()

I've seen two ways to implement the new method in a derived class. Method one: sub new { my $invocant = shift; my $class = ref($invocant) || $invocant; my $self = {}; bless($self, $class); $self = $self->SUPER::new( @_ ); …
simbabque
  • 53,749
  • 8
  • 73
  • 136
5
votes
3 answers

C# Cast Object to List of Base Class

I have the following class structure: public class Fruit { } public class Apple : Fruit { } And then I am using a method from the .net framework that gets me a property value from a class returned as an object. So, // values will be of type…
Nick Olsen
  • 6,299
  • 11
  • 53
  • 75
5
votes
2 answers

Making type trait work for all derived types

I have a type trait and concept which checks if an std::variant can hold a given type T. Now I have a type variant2 which derives from std::variant, and I want to use that type trait with the new variant2 type. How can I accomplish this…
glades
  • 3,778
  • 1
  • 12
  • 34
5
votes
5 answers

Blocking the possibility to create classes directly bypassing a factory

In a base class for all the models in our MVC system, I created a factory method BaseCLass::getNew() that returns an instance of the requested child class when called via SomeChildClass::getNew(). Now, I'm looking for a way to force the programmer…
shealtiel
  • 8,020
  • 18
  • 50
  • 82
5
votes
2 answers

Whether to extend interface, when base class already extends same interface

In C#, as shown in the code snippet below, is it correct/proper to extend the interface IFoo when declaring the class A, knowing that the class BaseClass extends the interface IFoo? Is it necessary to specify the interface IFoo here, and is it best…
5
votes
4 answers

Can I have a base class where each derived class has its own copy of a static property?

I have something like the following situation below: class Base { public static int x; public int myMethod() { x += 5; return x; } } class DerivedA : Base { } class DerivedB : Base { } I am trying to set…
ntsue
  • 2,325
  • 8
  • 34
  • 53