FAQ Database Discussion Community


Derived classes' functions not being called

c++,inheritance,virtual,derived-class,base-class
I am dealing with the base class Entity, and I want its derived classes (Player, Enemy, Bullet) to have collideWith() called I have attempted to get the derived functions of Entity's collideWith() to work, however, the base version is always called, which happens to be empty, even when I removed...

How to refer to parent class of base class from sub-sub-base-class static method without specifying base class name

php,subclass,static-methods,superclass,base-class
In PHP, I want to call a static method in the parent of the parent class from the sub-sub-class, without referring to the parent class of the parent class's name (please see the comment in the code below): class Base { public static function helloStatic() { return "Hello base!\n"; }...

How does method redirection takes place in super class and base class?

java,superclass,base-class
class HouseHold extends Customer { public void requestCoupon() { Transaction(); CouponCount = 20; } public double Transaction () { Payment += CouponPayment; return Payment; } } class GCustomer extends HouseHold { public double Transaction () { Payment += DisCPayment; return Payment; } } I'm making an object (A) of the...

C++ storing derived classes in a single vector with the derived classes not containg redifined methods

c++,inheritance,vector,derived-class,base-class
I have a program with a rather complex inheritance structure, so I won't use it to show my problem but the following structure which uses bad style to keep things simple: class A { public: int va1; int va2; string va3; virtual void fa1(int x1, string x2) { // method...

how to serialize a class without base class in protobuf C#

c#,serialization,protobuf-net,base-class
I have class that extend DictionaryBase class. when serialize this class with protobuf give below exception: Repeated data (a list, collection, etc) has inbuilt behaviour and cannot be subclassed this is my code : [protoContract] public class myClass :DictionaryBase { [protomember(1)] public int temp {get; set;} } DictionaryBase class is...

How to add global variables used by all tests in Javascript?

javascript,testing,code-reuse,base-class,code-duplication
I could not find how to remove code duplication in Javascript (basically what I would achieve in Java with base classes). The concrete example is (at least) the following code, which is common to all spec files (and potentially page objects, since I am testing with that pattern in protractor):...

Is an Abstract Class the same thing as a Base Class?

c++,oop,abstract-class,base-class,abstract-base-class
Is an Abstract Class the same thing as a Base Class? I occasionally see the term Base Class, but when I look up what it means, I tend to see "Abstract Class" thrown around. Are they just two words that mean basically the same thing?...

Does pointer to derived class create the Base class first or not?

c++,pointers,inheritance,derived-class,base-class
I have the following code #include <iostream> using namespace std; class B{ int i; public: B(){ cout << "Constructing B\n"; } void print(){ cout << "Printing from B with size : "<<sizeof(*this)<<endl; } }; class D:public B{ int i; public: D(){ cout << "Constructing D\n"; } void print(){ cout <<...

Initialize base class’s fields in subclass constructor in C#

c#,constructor,subclass,base-class
I have a base class with three field, but instead of initializing its field the normal way like this: class ParentClass { public string Name { get; set; } public string Family { get; set; } public string Address { get; set; } public ParentClass(string Name, string Family, string Address)...

Base to derived class conversion does not result in null

c#,casting,subclass,base-class
As long as I know, we can't directly convert a base class to a derived (sub) class, because the base is not an instance of the derived and thus it'll result in null. I have two classes, one derives from the other. I'm trying to figure out why I can...