Top "Downcast" questions

Downcasting permits an object of a superclass type to be treated as an object of any subclass type.

Cast the current object ($this) to a descendent class

I have a class where it may be necessary to change the object to a descendent class further down the …

php oop type-conversion downcast
How to downcast a Java object?

I am trying to understand Java's polymorphism, and I have one question about downcasting an object. Let's say for this …

java oop inheritance downcast
C++ - upcasting and downcasting

In my example: At upcasting, shouldn't the second d.print() call print "base"? Isn't it "d" derived object upcasted to …

c++ class inheritance downcast upcasting
Why can't static_cast be used to down-cast when virtual inheritance is involved?

Consider the following code: struct Base {}; struct Derived : public virtual Base {}; void f() { Base* b = new Derived; Derived* d = static_…

c++ virtual-inheritance downcast static-cast
C++ dynamic_cast - polymorphic requirement and downcasting

In the following code, while constructing obj in case 1, we construct a derived class object too, but its member functions …

c++ dynamic-cast downcast
Treating a forced downcast as optional will never produce 'nil'

I've been playing around with Swift and discovered that when down casting an object to be inserted into a dictionary, …

swift optional downcast forced-unwrapping
Best way to create a child object from its parent

Which is the best way to create a child given a parent with data? Would it be ok to have …

java inheritance downcast
How do I downcast in python

I have two classes - one which inherits from the other. I want to know how to cast to (or …

python downcast
Cast base instance to derived class (downcast) in C#

Suppose I have two classes: class Employee and class AdvancedEmployee:Employee I know something like this won't work, as I …

c# downcast
Why do we need Downcasting really?

I am trying to figure out why do I need Downcasting. I reread my notes from collage and found the …

java downcast