How to resolve “pure virtual method called”

By the time your destructor is called, the destructor of inherited classes has already been called. Within constructors and destructors, the dynamic type of the object can effectively be considered to be the same as the static type. That is, when you call virtual methods from within your constructors/destructors it’s not the overriden versions of … Read more

Are Polymorphism , Overloading and Overriding similar concepts? [closed]

Polymorphism can be achieved through overriding. Put in short words, polymorphism refers to the ability of an object to provide different behaviors (use different implementations) depending on its own nature. Specifically, depending on its position in the class hierarchy. Method Overriding is when a method defined in a superclass or interface is re-defined by one … Read more

Static methods and designing for inheritance

Inheritance clearly means a knowledge of the base class. @staticmethod is ignorant of the class it is ‘attached’ to(hence they earlier-not now-a-days-called it ‘unbound;’ now technically @staticmethod is not a method at all; it is a function. But @classmethod is fully aware of the class it is attached to; it is technically not a function, … Read more

Is Clojure object-oriented at its heart? (Polymorphism in seqs)

Idiomatic Clojure favors defining independent functions that operate on a very small set of core data structures; this unbundling of methods and data is a strong statement against object orientation and in favour of a functional style. Rich Hickey (creator of Clojure) has repeatedly stated the importance of this; for example here: “Clojure eschews the … Read more

Should I use polymorphism in javascript?

As said, JavaScript is a dynamic typed language based on prototypal inheritance, so you can’t really use the same approach of typed languages. A JS version of what you wrote, could be: function Shape(){ throw new Error(“Abstract class”) } Shape.prototype.printSurface = function () { throw new Error (“Not implemented”); } function Rect() { // constructor; … Read more

Static Binding and Dynamic Binding

Your example is dynamic binding, because at run time it is determined what the type of a is, and the appropriate method is called. Now assume you have the following two methods as well: public static void callEat(Animal animal) { System.out.println(“Animal is eating”); } public static void callEat(Dog dog) { System.out.println(“Dog is eating”); } Even … Read more

Vector that can have 3 different data types C++

EDIT: as of C++17, the standard library now includes the class template std::variant, which is quite similar to pre-existing solutions in boost. variant is a type-safe alternative to unions that allows multiple types to be joined using an “or” relationship, e.g., an std::variant<type1, type2, typ3> contains either a type1 OR a type2 OR a type3. … Read more

Force base method call

There isn’t and shouldn’t be anything to do that. The closest thing I can think of off hand if something like having this in the base class: public virtual void BeforeFoo(){} public void Foo() { this.BeforeFoo(); //do some stuff this.AfterFoo(); } public virtual void AfterFoo(){} And allow the inheriting class override BeforeFoo and/or AfterFoo